Trainer -- Regression

On this Page


This is a Transform type Snap that builds model for a regression dataset. In the Snap's settings, you can select the target field in the dataset, algorithm, and configure parameters for the selected algorithm.

If you want to build the model on regression dataset, use Trainer -- Classification Snap instead.

Input and Output

Expected input: The regression dataset.

Expected output: A serialization of the model, and metadata which are not human-readable. Additionally, the output includes a human-readable representation of the model if the Readable checkbox is selected.

Expected upstream Snap: Any Snap that generates a regression dataset document. For example, CSV Generator, JSON Generator, or a combination of File Reader and JSON Parser.

Expected downstream Snap: Snaps that require a model input. For example, the Predictor (Regression) Snap. Alternatively, any Snap that stores the model to be used in another pipeline. For example, a combinationof JSON Formatter and File Writer.


  • The data from upstream Snap must be in tabular format (no nested structure). 
  • This Snap automatically derives the schema (field names and types) from the first document. Therefore, the first document must not have any missing values.

Configuring Accounts

Accounts are not used with this Snap.

Configuring Views


This Snap has exactly one document input view.
OutputThis Snap has exactly one document output view.
ErrorThis Snap has at most one document error view.



Limitations and Known Issues



Snap Settings

LabelRequired. The name for the Snap. Modify this to be more specific, especially if there are more than one of the same Snap in the pipeline.
Label field

Required. The label or output field in the dataset. This must be numeric. This is the field that the model will be trained to predict.

Default value: None

Example: $price


Required. The regression algorithm to be used to build the model. There are four regression algorithms currently available:

  • K-Nearest Neighbors
  • Linear Regression
  • Decision Stump
  • Random Forests

The implementations are from WEKA, an open source machine learning library in Java.

Default value: K-Nearest Neighbors


The parameters to be applied on the selected regression algorithm. Each algorithm has a different set of parameters to be configured in this property. If this property is left blank, the default values are applied for all the parameters. If specifying multiple parameters, separate them with a comma ",".

See Options for Algorithms section below for details.

Default value: None


  • batch_size = 120
  • batch_size = 120, collapse_tree = true

Select this to output the model in human-readable format. When selected, a $readable field is added to the output, this displays the model in a readable format.

Default value: Not selected

Snap Execution

Select one of the three modes in which the Snap executes. Available options are:

  • Validate & Execute: Performs limited execution of the Snap, and generates a data preview during Pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during Pipeline runtime.
  • Execute only: Performs full execution of the Snap during Pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Best Practices

Using Type Converter Snap Upstream

In some cases, the numerical fields may be represented as a string. You can use the Type Converter Snap to convert data into appropriate types before feeding into the Trainer (Regression) Snap.

Algorithm Selection 

In order to choose the best possible algorithm for your dataset, use the Cross Validator (Regression) Snap to perform k-fold cross validation on the dataset. The algorithm that produces the best accuracy is likely to be the one most suitable for your dataset. Apply the same algorithm for your dataset in the Trainer (Regression) Snap to built the model. 

Options for Algorithms

 Click here to expand...

This section lists all applicable parameters for each algorithm along with their default values. 

K-Nearest Neighbors

Option Name
Option Data Type
Default Value
knnint1Set the number of neighbors the learner will use.
batch_sizeint100Set the preferred batch size for batch prediction.
cross_validatebooleanfalseSet whether the hold-one-out cross-validation will be used to select the best k-value.
[weight_none, weight_inverse, weight_similarity]
weight_noneSet the distance weighting method used. 
do_not_check_capabilitiesbooleanfalseEnable capability-check.
mean_squaredbooleanfalseSet whether the mean squared error is used rather than mean absolute error when doing cross-validation.
[LinearNNSearch, BallTree, CoverTree, KDTress, FilteredNeighbourSearch]
LinearNNSearchSet the nearestNeighbourSearch algorithm to be used for finding nearest neighbor(s).
num_decimal_placesint2Set the number of decimal places.
window_sizeint0 (no window size)Set the maximum number of instances allowed in the training pool.

Linear Regression

Option Name
Option Data Type
Default Value
[slection_none, selection_m5, selection_greedy]
selection_m5Set the attribute selection method to use.
batch_sizeint100Set the preferred batch size for batch prediction.
do_not_check_capabilitiesbooleanfalseSet whether not to check capabilities.
eliminate_colinear_attributesbooleantrueSet whether to try to eliminate colinear attributes.
minimalbooleanfalseSet to conserve memory, don't keep dataset header and means/stdevs.
num_decimal_placesint4Set the number of decimal places.
ridgedouble1.00E-08Set the value of the ridge parameter.

Decision Stump

Option Name
Data Type
Default Value
batch_sizeint100Set the preferred batch size for batch prediction.
do_not_check_capabilitiesbooleanfalseEnable capability-check.
num_decimal_placesint2Set the number of decimal places.

Random Forests

Option Name
Data Type
Default Value
bag_size_percentint100Specify the size of each bag, as a percentage of the training set size.
batch_sizeint100Set the preferred batch size for batch prediction.
break_ties_randomlybooleanfalseSet whether to break ties randomly when several attributes look equally good.
calc_out_of_bagbooleanfalseSet whether to calculate the out-of-bag error.
compute_attribute_importancebooleanfalseSet whether compute and output attribute importance (mean impurity decrease method)
do_not_check_capabilitiesbooleanfalseEnable capability-check.
max_depthint0Set the maximum depth of the tree, 0 for unlimited.
num_decimal_placesint2Set the number of decimal places.
num_execution_slotsint1Set the  number of execution slots.
num_featuresint0Set the  number of attributes to randomly investigate.
num_iterationsint100Set the number of iterations.
seedint1Set the seed for random number generator.
store_out_of_bag_predictionsbooleanfalseSet whether to store out-of-bag predictions in internal evaluation object.


Heating Load Prediction – Model Training

This pipeline demonstrates training a model to predict whether a weighing scale is balanced. The regression algorithm is selected based on the algorithm evaluation in the Cross Validator (Regression) Snap's example

Download this pipeline.

 Understanding the pipeline


The input is generated by the CSV Generator Snap and is composed of the following fields:

  • Relative Compactness
  • Surface Area
  • Wall Area
  • Roof Area
  • Overall Height
  • Orientation
  • Glazing Area
  • Glazing Area Distribution
  • Heating Load

This dataset has been sourced from UCI Dataset Archive.


Use Trainer (Regression) Snap to train the model for the dataset.

Data Preparation

This input document is passed through the Type Converter Snap that is configured to automatically detect and convert the data types. In any ML pipeline, you must first analyze the input document using the Profile Snap and the Type Inspector Snap to ensure that there are no null values or that the data types are accurate. This step is skipped in this example for simplicity's sake.

Below is a preview of the output from the Type Converter Snap:

Model Training

Since the training algorithm was evaluated in the Cross Validator (Regression) Snap, the Trainer (Regression) Snap is configured with the same settings as shown below:

The output from the Snap is the model for the dataset as shown below:

The model is written into a file using the File Writer Snap which is configured as shown below:

Download this pipeline.

Additional Example

The following use case demonstrates a real-world scenario for using this Snap:


  File Modified

File Energy_Efficiency_Train_Model.slp

Nov 09, 2018 by Mohammed Iqbal

See Also

Snap Pack History

 Click to view/expand

4.27 (main12833)

  • No updates made.

4.26 (main11181)

  • No updates made.

4.25 (main9554)

  • No updates made.

4.24 (main8556)

  • No updates made.

4.23 (main7430)

  • No updates made.

4.22 (main6403)

  • No updates made.

4.21 (snapsmrc542)

  • No updates made.

4.20 Patch mlcore8770

  • Adds the log4j dependency to the ML Core Snaps to resolve the "Could not initialize class org.apache.log4j.LogManager" error. 

4.20 (snapsmrc535)

  • No updates made.

4.19 (snapsmrc528)

  • No updates made.

4.18 (snapsmrc523)

  • No updates made.

4.17 Patch ALL7402

  • Pushed automatic rebuild of the latest version of each Snap Pack to SnapLogic UAT and Elastic servers.

4.17 (snapsmrc515)

  • New Snap: Introducing the Clustering Snap that performs exploratory data analysis to find hidden patterns or groupings in data.
  • Enhanced the AutoML Snap. You can now:
    • Select algorithms to derive the top models.
    • Input the best model generated by another AutoML Snap from a previous execution.
    • View an interactive HTML report that contains statistics of up to 10 models.
  • Added the Snap Execution field to all Standard-mode Snaps. In some Snaps, this field replaces the existing Execute during preview check box.

4.16 (snapsmrc508)

  • New Snap: Introducing the AutoML Snap, which lets you automate the process of selecting machine learning algorithms and tuning hyperparameters. This Snap gives the best predictive model within the specified time limit.

4.15 (snapsmrc500)

  • New Snap Pack. Perform data modeling operations such as model training, cross-validation, and model-based predictions. Additionally, you can also execute Python scripts remotely. Snaps in this Snap Pack are: 
    • Cross Validator -- Classification
    • Cross Validator -- Regression
    • Predictor -- Classification
    • Predictor -- Regression
    • Remote Python Script
    • Trainer -- Classification
    • Trainer -- Regression
  • Releases the Remote Python Executor account and the Remote Python Executor Dynamic account for the Remote Python Script Snap.