Icon

PMML - Machine Learning Case - MLP - Apply via Python

<p>A data preparation and model building for "RProp MLP Learner" - also apply the resulting PMML model file with Python</p>

URL: Parameter Optimization Video - KNIME TV - YouTube https://youtu.be/IlqepyIba6Y
URL: ML Algorithms and the Art of Parameter Selection - KNIME Blog https://www.knime.com/blog/machine-learning-algorithms-and-the-art-of-hyperparameter-selection
URL: Medium: About Machine Learning — How it Fails and Succeeds https://medium.com/low-code-for-advanced-data-science/about-machine-learning-how-it-fails-and-succeeds-9f3ab7cb9b00
URL: Medium: KNIME — Machine Learning and Artificial Intelligence — A Collection https://medium.com/low-code-for-advanced-data-science/knime-machine-learning-and-artificial-intelligence-a-collection-12e0f7d83b50
URL: KNIME Forum (83474) - apply PMML Model via Python https://forum.knime.com/t/pmml-export-usage-at-python-enviroment/83474/2?u=mlauber71
URL: PMML models providing probabilities - KNIME Forum (13244) https://forum.knime.com/t/export-pmml-that-outputs-class-probabilities/13244/2?u=mlauber71

A data preparation and model building for "RProp MLP Learner" - also apply the resulting PMML model file with Python

https://forum.knime.com/t/pmml-export-usage-at-python-enviroment/83474/2?u=mlauber71

Apply the model using KNIME nodes

import knime.scripting.io as knio

import pandas as pd

from pypmml import Model



# Get the PMML model path from flow variables

var_path_pmml = knio.flow_variables["file_path"]



# Load the PMML model using pypmml

model = Model.load(var_path_pmml)



# Load the input data from KNIME input tables and reset its index

df = knio.input_tables[0].to_pandas().reset_index(drop=True)



# Apply the PMML model to the input data (with transformations included in the PMML)

predictions = model.predict(df)



# Convert predictions to a DataFrame if necessary and reset its index

predictions_df = pd.DataFrame(predictions).reset_index(drop=True)



# Concatenate the original DataFrame and predictions along axis=1

output_df = pd.concat([df, predictions_df], axis=1)



# Print the transformed data along with predictions (optional)

print(output_df)



# Output the result back to KNIME

knio.output_tables[0] = knio.Table.from_pandas(output_df)

*Target*
Column Filter
train.parquetTarget 0/1 - target variablerow_id = ID column
Parquet Reader
bring the Target backtest
Joiner
BINARY_RPROP_MLP_03_normalizer.pmml
PMML Reader
BINARY_RPROP_MLP_03_normalizer.pmml
PMML Writer
75% for training 25 % for testing
Partitioning
v_path_pmml
URL to File Path (Variable)
v_path_pmml
Path to String (Variable)
validate_normalized.table
Table Writer
Apply the PMML modelusing Python code
Python Script
train_normalized.table
Table Writer
Merge Variables
row_idexclude
Column Filter
BINARY_RPROP_MLP_01_missings.pmmlv_path_pmml
PMML Writer
test
MultiLayerPerceptron Predictor
BINARY_RPROP_MLP_01_missings.pmml
PMML Reader
BINARY_RPROP_MLP_02_cat_to_num.pmml
PMML Writer
train
RProp MLP Learner
BINARY_RPROP_MLP_02_cat_to_num.pmml
PMML Reader
BINARY_RPROP_MLP_04_table_specs.table
Table Reader
BINARY_RPROP_MLP_04_table_specs.table
Table Writer
RProp MLP - Data Preparation Binary - Compute
Activate Conda Environmentbased on Operating SystemWindows or macOSconfigure how to handle the environmentdefault = just check the names
conda_environment_pmml
validate
RProp MLP - Data Preparation Binary - Apply
Concatenate
test (25%)
RProp MLP - Data Preparation Binary - Apply
BINARY_RPROP_MLP.pmml
PMML Reader
validate.parquetTarget 0/1 - target variablerow_id = ID column
Parquet Reader
BINARY_RPROP_MLP.pmmlv_path_pmml
PMML Writer
Binary Classification Inspector

Nodes

Extensions

Links