datatable.models module contains built-in machine learning models and dataset preparation utilities. All models operate directly on datatable Frame objects, with no conversion to pandas or numpy required.
Ftrl
Ftrl implements the Follow the Regularized Leader (FTRL-Proximal) online learning algorithm. It supports binomial logistic regression, multinomial classification, and regression for continuous targets. Training is fully parallel using the Hogwild approach.
Features are hashed with a 64-bit function: integers and booleans via identity, floats via mantissa trimming, strings via Murmur2, and date/time types via their internal integer representation.
Constructor
Learning rate
α in the per-coordinate FTRL-Proximal algorithm. Controls the step size.Smoothing parameter
β in the per-coordinate FTRL-Proximal algorithm.L1 regularization parameter
λ₁. Encourages sparsity in the model weights.L2 regularization parameter
λ₂. Penalizes large weights.Number of bins used by the hashing trick. Larger values reduce hash collisions.
Number of training epochs. Fractional values are supported.
Explicit feature interaction pairs. Each inner list specifies column names whose hash values are combined.
Determines the type of model to build.
"auto" infers the type from the target column.Use
float64 arithmetic internally instead of float32.Methods
fit(X, y)
Train the model on feature frame X and target frame y. Can be called multiple times to continue training.
predict(X)
Return predictions for frame X as a new Frame. Output type depends on model_type.
reset()
Reset model weights to their initial state without changing hyperparameters.
Key properties
| Property | Type | Description |
|---|---|---|
model_type | str | The model type to build ("auto", "binomial", etc.). |
model_type_trained | str | The model type that was actually trained. |
feature_importances | Frame | Feature importances computed during training. |
labels | Frame | Classification labels (multinomial/binomial). |
params | namedtuple | All hyperparameters as a named tuple. |
model | Frame | The model’s z and n coefficient columns. |
colnames | List[str] | Column names of the training frame. |
mantissa_nbits | int | Mantissa bits used when hashing float features. |
Example
LinearModel
LinearModel implements a linear model with stochastic gradient descent (SGD) learning. It supports linear regression, binomial classification, and multinomial classification. Both fit and predict are fully parallel.
Constructor
Initial learning rate.
Decay coefficient for
"time-based" and "step-based" learning rate schedules.Drop rate for the
"step-based" learning rate schedule.Learning rate schedule. Controls how
eta0 changes across epochs.L1 regularization parameter.
L2 regularization parameter.
Number of training epochs.
Type of model to build.
Use
float64 arithmetic instead of float32.If
True, an explicit “negative” class is added for multinomial classification.Seed for quasi-random row shuffling during SGD.
Methods
fit(X, y)
Train the model on feature frame X and target frame y.
predict(X)
Return predictions for frame X.
is_fitted()
Return True if the model has been trained, False otherwise.
reset()
Clear trained weights and return the model to its initial untrained state.
Example
aggregate(frame, ...)
Aggregate a Frame into clusters. Each cluster consists of a set of member rows and is represented by one exemplar row. Useful for summarizing large datasets before visualization or modeling.
Input frame with numeric or string columns. Non-numeric columns are ignored in the ND aggregation algorithm.
Minimum number of rows required for aggregation to run. Frames smaller than this threshold have all rows treated as exemplars.
Number of bins for 1D aggregation.
Maximum number of exemplars produced by the ND algorithm. The exact count may vary across runs due to parallelization.
Column count at which the projection method is used for ND aggregation.
Seed for the projection method’s random number generator.
Fixed bubble radius for the ND algorithm. When set,
nd_max_bins has no effect. Use with caution on large data — the number of exemplars can equal the number of rows.- Exemplars frame — shape
(nexemplars, ncols + 1). Contains the original columns plus amembers_countcolumn (int32) indicating how many rows each exemplar represents. - Members frame — shape
(nrows, 1). Theexemplar_idcolumn (int32) maps each input row to its exemplar’s row index.
Example
kfold(nrows, nsplits)
Split nrows rows into nsplits sequential train/test folds. The i-th fold uses rows [i·nrows/nsplits, (i+1)·nrows/nsplits) as the test set and all remaining rows as training data.
Total number of rows to split. Must match the row count of the frame you apply the selectors to.
Number of folds. Must be at least
2 and no larger than nrows.List[Tuple] — a list of nsplits tuples (train_rows, test_rows), where each component is a row selector (a Python range or a single-column Frame).
kfold_random(nrows, nsplits, seed=None)
Like kfold, but assigns rows to folds randomly so each row has an equal probability of ending up in any fold. Row indices within each fold are sorted.
Total number of rows to split.
Number of folds. Must be at least
2 and no larger than nrows.Random seed. Providing the same seed guarantees reproducible splits across runs.
List[Tuple] — a list of nsplits tuples (train_rows, test_rows).