train_classification_gpu
Train and store a classification model to be loaded at a later point for prediction.
The output will consist of a new column with the trained model’s predictions on the training data, as well as a saved and named model file that can be used in other projects for prediction of new data.
Optionally, if a second output column name is provided, the model’s predicted probabilities will also be returned.
A detailed guide on how to configure this step for model tuning and performance evaluation can be found here.
Should contain the target column and the feature columns you wish to use in the model.
One or two columns containing the model’s predictions. If two column names are provided, the second column will contain the model’s predicted probabilities.
Zip file containing the trained model and associated information.
Train a Catboost classifier. I.e. gradient boosted decision trees with support for categorical variables and missing values.
Target variable (labels). Name of the column that contains your target values (labels).
Name of the positive class. In binary classification, usually the class you’re most interested in, for example the label/class corresponding to successful lead conversion in a lead score model, the class corresponding to a customer who has churned in a churn prediction model, etc.
If provided, will automaticall measure the performance (accuracy, precision, recall) of the model on this class, in addition to averages across all classes. If not provided, only summary metrics will be reported.
Maximum number of classes in the target variable. If there are more classes than this, the least frequent classes will be grouped together into a single class called “others”. Reducing the number of classes in the target variable can help improve model performance, especially when the number of classes is very large, some classes are very rare, or the dataset doesn’t have sufficient samples for all classes. Raising this significantly might lead to much longer training times.
Values must be in the following range:
2 ≤ max_classes ≤ 100
Importance of each feature in the model. Whether and how to measure each feature’s contribution to the model’s predictions. The higher the value, the more important the feature was in the model. Only relative values are meaningful, i.e. the importance of a feature relative to other features in the model.
Also note that feature importance is usually meaningful only for models that fit the data well.
The default (null
, true
or "native"
) uses the classifier’s native feature importance measure, e.g.
prediction-value-change in the case
of Catboost, Gini importance
in the case of scikit-learn’s DecisionTreeClassifier, and the mean of absolute coefficients in the case of
logistic regression.
When set to "permutation"
, uses permutation importance,
i.e. measures the decrease in model score when a single feature’s values are randomly shuffled. This is
considerably slower than native feature importance (the model needs to be evaluated an additional k*n times,
where k is the number of features and n the number of repetitions to average over). On the positive side it is
model-agnostic and doesn’t suffer from bias towards high cardinality features (like some tree-based feature
importances). On the negative side, it can be sensitive to strongly correlated features, as the unshuffled
correlated variable is still available to the model when shuffling the original variable.
When set to false
, no feature importance will be calculated.
Values must be one of the following:
True
False
native
permutation
null
Toggle encoding of feature columns.
When enabled, Graphext will auto-convert any column types to the numeric type before
fitting the model. How this conversion is done can be configured using the feature_encoder
option below.
Configures encoding of feature columns.
By default (null
), Graphext chooses automatically how to convert any column types the model
may not understand natively to a numeric type.
A configuration object can be passed instead to overwrite specific parameter values with respect to their default values.
Numeric encoder. Configures encoding of numeric features.
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
Mean
Median
MostFrequent
Const
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
Further parameters passed to the scaler
function.
Details depend no the particular scaler used.
Boolean encoder. Configures encoding of boolean features.
Ordinal encoder. Configures encoding of categorical features that have a natural order.
Category encoder. May contain either a single configuration for all categorical variables, or two different configurations for low- and high-cardinality variables. For further details pick one of the two options below.
Multilabel encoder.
Configures encoding of multivalued categorical features (variable length lists of categories,
or the semantic type list[category]
for short). May contain either a single configuration for
all multilabel variables, or two different configurations for low- and high-cardinality variables.
For further details pick one of the two options below.
Datetime encoder. Configures encoding of datetime (timestamp) features.
Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
A list of numerical components to extract. Will create one numeric column for each component.
A list of cyclical time features to extract. “Cycles” are numerical transformations of features that should be represented on a circle. E.g. months, ranging from 1 to 12, should be arranged such that 12 and 1 are next to each other, rather than on opposite ends of a linear scale. We represent such cyclical time features on a circle by creating two columns for each original feature: the sin and cos of the numerical feature after appropriate scaling.
Whether to include the epoch as new feature (seconds since 01/01/1970).
Whether and how to impute (replace/fill) missing values.
Values must be one of the following:
Mean
Median
MostFrequent
Const
None
Whether and how to scale the final numerical values (across a single column).
Values must be one of the following:
Standard
Robust
KNN
None
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
Embedding/vector encoder.
Configures encoding of multivalued numerical features (variable length lists of numbers, i.e. vectors, or the semantic type list[number]
for short).
Text encoder. Configures encoding of text (natural language) features. Currently only allows Tf-Idf embeddings to represent texts. If you wish to use other embeddings, e.g. semantic, Word2Vec etc., transform your text column first using another step, and then use that result instead of the original texts.
include_text_features
below to active it.Toggle the addition of a column using 0s and 1s to indicate where an input column contained missing values.
Parameters to be passed to the text encoder (Tf-Idf parameters only for now). See scikit-learn’s documentation for detailed parameters and their explanation.
How many output features to generate. The resulting Tf-Idf vectors will be reduced to these many dimensions (columns) using scikit-learn’s truncated SVD. This performs a kind of latent semantic analysis. By default we will reduce to 200 components.
Values must be in the following range:
2 ≤ n_components ≤ 1024
How to scale the encoded (numerical columns).
Values must be one of the following:
Euclidean
KNN
Norm
None
Whether to include or ignore text columns during the processing of input data.
Enabling this will convert texts to their TfIdf representation. Each text will be
converted to an N-dimensional vector in which each component measures the relative
“over-representation” of a specific word (or n-gram) relative to its overall
frequency in the whole dataset. This is disabled by default because it will
often be better to convert texts explicitly using a previous step, such as
embed_text
or embed_text_with_model
.
CatBoost configuration parameters. You can check the official documentation for more details about Catboost’s parameters here.
The maximum depth of the tree.
Values must be in the following range:
2 ≤ depth ≤ 16
Number of iterations. The maximum number of trees that can be built when solving machine learning problems. When using other parameters that limit the number of iterations, the final number of trees may be less than the number specified in this parameter.
Values must be in the following range:
1 ≤ iterations < inf
Maximum cardinality of variables to be one-hot encoded. Use one-hot encoding for all categorical features with a number of different values less than or equal to this value. Other variables will be target-encoded. Note that one-hot encoding is faster than the alternatives, so decreasing this value makes it more likely slower methods will be used. See CatBoost details for further information.
Values must be in the following range:
2 ≤ one_hot_max_size < inf
The maximum number of features that can be combined when transforming categorical variables. Each resulting combination consists of one or more categorical features and can optionally contain binary features in the following form: “numeric feature > value”.
Values must be in the following range:
1 ≤ max_ctr_complexity ≤ 4
Coefficient at the L2 regularization term of the cost function.
Values must be in the following range:
0.0 º l2_leaf_reg < inf
The number of splits for numerical features.
Values must be in the following range:
1 ≤ border_count ≤ 65535
The amount of randomness to use for scoring splits. Use this parameter to avoid overfitting the model. The value multiplies the variance of a random variable (with zero mean) that is added to the score used to select splits when a tree is grown.
Values must be in the following range:
0 º random_strength < inf
The method for processing missing values in the input dataset. Possible values:
- “Forbidden”: Missing values are not supported, their presence is interpreted as an error.
- “Min”: Missing values are processed as the minimum value (less than all other values) for the feature. It is guaranteed that a split that separates missing values from all other values is considered when selecting trees.
- “Max”: Missing values are processed as the maximum value (greater than all other values) for the feature. It is guaranteed that a split that separates missing values from all other values is considered when selecting trees.
Using the Min or Max value of this parameter guarantees that a split between missing values and other values is considered when selecting a new split in the tree.
Values must be one of the following:
Forbidden
Min
Max
Boosting type. Boosting scheme. Possible values are
- Ordered: Usually provides better quality on small datasets, but it may be slower than the Plain scheme.
- Plain: The classic gradient boosting scheme.
Values must be one of the following:
Ordered
Plain
Random subspace method.
The percentage of features to use at each split selection, when features are selected over again at random. The value null
is equivalent to 1.0 (all features). You can set this to values < 1.0 when the dataset has many features (e.g. > 20) to speed up training.
Values must be in the following range:
0 º rsm ≤ 1.0
The random seed used for training.
Whether and how to limit memory usage. Select the maximum Ram used using strings like “2GB” or “100mb” (non case_sensitive).
Whether and how to assign weights to different predicted classes. The options are:
- null: No class weighting
- Balanced: Inversely proportional to the number of samples/rows in each class
- SqrtBalanced: Using the square root of the “Balanced” option.
Values must be one of the following:
Balanced
SqrtBalanced
None
None
Configure model validation. Allows evaluation of model performance via cross-validation using custom metrics. If not specified, will by default perform 5-fold cross-validation with automatically selected metrics.
Number of train-test splits to evaluate the model on.
Will split the dataset into training and test set n_splits
times, train on the former
and evaluate on the latter using specified or automatically selected metrics
.
Values must be in the following range:
1 ≤ n_splits < inf
What proportion of the data to use for testing in each split.
If null
or not provided, will use k-fold cross-validation
to split the dataset. E.g. if n_splits
is 5, the dataset will be split into 5 equal-sized parts.
For five iterations four parts will then be used for training and the remaining part for testing.
If test_size
is a number between 0 and 1, in contrast, validation is done using a
shuffle-split
approach. Here, instead of splitting the data into n_splits
equal parts up front, in each iteration
we randomize the data and sample a proportion equal to test_size
to use for evaluation and the remaining
rows for training.
Values must be in the following range:
0 º test_size < 1
Whether to split the data by time. Most recent data will be used for testing and previous data for training. Assumes data is passed already sorted ascending by time.
One or more metrics/scoring functions to evaluate the model with. When none is provided, will measure default metrics appropriate for the prediction task (classification vs. regression determined from model or type of target column). See sklearn model evaluation for further details.
Configure hypertuning. Configures the optimization of model hyper-parameters via cross-validated grid- or randomized search.
Which search strategy to use for optimization.
Grid search explores all possible combinations of parameters specified in params
.
Randomized search, on the other hand, randomly samples iterations
parameter combinations
from the distributions specified in params
.
Values must be one of the following:
grid
random
How many randomly sampled parameter combinations to test in randomized search.
Values must be in the following range:
1 º iterations < inf
Configure model validation. Allows evaluation of model performance via cross-validation using custom metrics. If not specified, will by default perform 5-fold cross-validation with automatically selected metrics.
Number of train-test splits to evaluate the model on.
Will split the dataset into training and test set n_splits
times, train on the former
and evaluate on the latter using specified or automatically selected metrics
.
Values must be in the following range:
1 ≤ n_splits < inf
What proportion of the data to use for testing in each split.
If null
or not provided, will use k-fold cross-validation
to split the dataset. E.g. if n_splits
is 5, the dataset will be split into 5 equal-sized parts.
For five iterations four parts will then be used for training and the remaining part for testing.
If test_size
is a number between 0 and 1, in contrast, validation is done using a
shuffle-split
approach. Here, instead of splitting the data into n_splits
equal parts up front, in each iteration
we randomize the data and sample a proportion equal to test_size
to use for evaluation and the remaining
rows for training.
Values must be in the following range:
0 º test_size < 1
Whether to split the data by time. Most recent data will be used for testing and previous data for training. Assumes data is passed already sorted ascending by time.
One or more metrics/scoring functions to evaluate the model with. When none is provided, will measure default metrics appropriate for the prediction task (classification vs. regression determined from model or type of target column). See sklearn model evaluation for further details.
Metric used to select best model.
Values must be one of the following:
accuracy
balanced_accuracy
f1_micro
f1_macro
f1_samples
f1_weighted
precision_micro
precision_macro
precision_samples
precision_weighted
recall_micro
recall_macro
recall_samples
recall_weighted
roc_auc
roc_auc_ovr
roc_auc_ovo
roc_auc_ovr_weighted
roc_auc_ovo_weighted
The parameter values to explore. Allows tuning of any and all of the parameters that can be set also as constants in the “params” attribute.
Keys in this object should be strings identifying parameter names, and values should be
lists of values to explore for that parameter. E.g. "depth": [3, 5, 7]
.
List of depths values to explore.
List of iterations values to explore.
List of values configuring max cardinality for one-hot encoding.
List of values configuring variable combination complexity.
List of leaf regularization strengths.
List of border counts.
List of random strengths.
List of criterion values to explore.
List of splitter values to explore.
List of max_depth values to explore.
List of min_samples_split values to explore.
List of min_samples_leaf values to explore.
List of max_leaf_nodes values to explore.
List of max_features values to explore.
List of ccp_alpha values to explore.
Seed for random number generator ensuring reproducibility.
Values must be in the following range:
0 ≤ seed < inf
Sort the data before training.
If the data is not already sorted by time, you can sort it here. This is useful when you want to split the data
by time, for example to train on older data and test on newer data (see the time_split
parameter in validation
configurations). If the data is already sorted by time, you can ignore this parameter.
One or more column to sort by.
Sort order.
Whether to sort in ascending or descending order. If the single value true
is provided, or no value is specified,
all columns will be sorted in ascending order. If a single false
is provided, all columns will be sorted in descending
order. If an array of booleans is provided, each column will be sorted according to the corresponding boolean value.
Was this page helpful?