Icon

01 Analyze Data by Training a Decision Tree

<p><strong>Analyze Data: Training a Decision Tree</strong></p><p>This workflow is an example of how to <strong>train and evaluate a basic machine learning model</strong> for a churn prediction task.</p><p>In this case, we train and apply a <strong>Decision Tree</strong> algorithm, however, the <em>Learner-Predictor</em> construct is common to all supervised algorithms.</p>

URL: KNIME Learning Center https://www.knime.com/learning
URL: KNIME Cheat Sheet: Building a KNIME workflow for beginners https://www.knime.com/cheat-sheets/building-knime-workflow-beginners
URL: KNIME Cheat Sheet: Machine learning with KNIME Analytics Platform https://www.knime.com/files/machine-learning-with-knime.pdf
URL: YouTube: Training and Applying Decision Trees in KNIME https://youtu.be/UeQAHusmwbI?si=bZ2v5rS350D1iJyJ
URL: YouTube: Behind the Scenes of the Decision Tree with KNIME https://youtu.be/8dxH_Arc4QM?si=9uw5T4BxyfzDg8GY
URL: KNIME Blog: Predict Customer Churn with a Low-Code ML Solution https://www.knime.com/blog/predict-customer-churn-low-code-ml-example
URL: Webinar: KNIME101: Machine Learning for Beginners with KNIME https://www.knime.com/events/knime101-machine-learning-beginners-knime

Pre-processing (data preparation)
Read data from different files
  • CallsData.xls: Customer activity

  • ContractData.csv: Information about customers

Color Churn

Assign color coding to data:

  • 0 -> Blue

  • 1 -> Red

Conversions

Convert "Churn" and "Area Code" to String

Partitioning

Split data into training set (80%) and test set (20%)

How to train a Decision Tree model?

Step 1: Add the "Decision Tree Learner" node to the workflow and select it to open the configuration window.

Step 2: Set the "Class column" to "Churn" and "Quality measure" to "Gini index".

Step 3: Click "Apply and Execute" to train the model. Investigate the view of the Decision Tree (click magnifier in the node action bar).

How to evaluate a Decision Tree model?


Step 1: Add the "Decision Tree Predictor" node to the workflow.

Step 2: Connect the output of "Decision Tree Learner" node to Port 0 andthe test set to Port 1. Execute the node.

Step 3: Connect the output containing the predictions to the "ROC Curve" and "Scorer" node to evaluate the model on various evaluation measures.

Analyze Data: Training a Decision Tree


This workflow is an example of how to train and evaluate a basic machine learning model for a churn prediction task.

In this case, we train and apply a Decision Tree algorithm, however, the Learner-Predictor construct is common to all supervised algorithms.

Model training

Train the Decision Tree with the "Decision Tree Learner" node. Write the trained model to a .pmml file with the "Model Writer" node.

Model evaluation

Apply the trained Decision Tree to the test set with the "Decision Tree Predictor" node. Evaluate the prediction using the "ROC Curve" and "Scorer" nodes.

Workflow complete!

Keep the momentum going by exploring Just KNIME It! on the Hub to challenge yourself and see how these nodes can be integrated into more complex workflows and use cases.

Join input dataon "Area Code"and "Phone"
Joiner
Top: Training setBottom: Test set
Table Partitioner
Apply trainedDecision Tree
Decision Tree Predictor
Area under the Curve
ROC Curve
Class column:Churn
Decision Tree Learner
Convert "Churn" and"Area Code" to String
Number to String
Color databy "Churn" values
Color Manager
Write trained modelworkflow data area
PMML Writer
ReadCallsData.xls
Excel Reader
Performance scoring:Evaluate accuracy
Scorer
ReadContractData.csv
CSV Reader

Nodes

Extensions

Links