sklearn_base

create_sklearn_model(model_constructor, model_args, output_transformer=None)[source]
str_sklearn_model(model)[source]

Creates a cleaned string representation of the model with line breaks and indentations removed

Parameters

model – the sklearn model for which to generate the cleaned string representation

Returns

the string representation

class AbstractSkLearnVectorRegressionModel(model_constructor, **model_args)[source]

Bases: sensai.vector_model.VectorRegressionModel, abc.ABC

Base class for models built upon scikit-learn’s model implementations

__init__(model_constructor, **model_args)
Parameters
  • model_constructor – the sklearn model constructor

  • model_args – arguments to be passed to the sklearn model constructor

with_sklearn_input_transformer(sklearn_input_transformer) sensai.sklearn.sklearn_base.AbstractSkLearnVectorRegressionModel
Parameters

sklearn_input_transformer – an optional sklearn preprocessor for normalising/scaling inputs

Returns

self

with_sklearn_output_transformer(sklearn_output_transformer)
Parameters

sklearn_output_transformer – an optional sklearn preprocessor for normalising/scaling outputs

Returns

self

class AbstractSkLearnMultipleOneDimVectorRegressionModel(model_constructor, **model_args)[source]

Bases: sensai.sklearn.sklearn_base.AbstractSkLearnVectorRegressionModel, abc.ABC

Base class for models which use several sklearn models of the same type with a single output dimension to create a multi-dimensional model (for the case where there is more than one output dimension)

__init__(model_constructor, **model_args)
Parameters
  • model_constructor – the sklearn model constructor

  • model_args – arguments to be passed to the sklearn model constructor

get_sklearn_model(predicted_var_name=None)
class AbstractSkLearnMultiDimVectorRegressionModel(model_constructor, **model_args)[source]

Bases: sensai.sklearn.sklearn_base.AbstractSkLearnVectorRegressionModel, abc.ABC

Base class for models which use a single sklearn model with multiple output dimensions to create the multi-dimensional model

__init__(model_constructor, **model_args)
Parameters
  • model_constructor – the sklearn model constructor

  • model_args – arguments to be passed to the sklearn model constructor

class AbstractSkLearnVectorClassificationModel(model_constructor, use_balanced_class_weights=False, use_label_encoding=False, **model_args)[source]

Bases: sensai.vector_model.VectorClassificationModel, abc.ABC

__init__(model_constructor, use_balanced_class_weights=False, use_label_encoding=False, **model_args)
Parameters
  • model_constructor – the sklearn model constructor

  • model_args – arguments to be passed to the sklearn model constructor

  • use_balanced_class_weights – whether to compute class weights from the training data and apply the corresponding weight to each data point such that the sum of weights for all classes is equal. This is achieved by applying a weight proportional to the reciprocal frequency of the class in the (training) data. We scale weights such that the smallest weight (of the largest class) is 1, ensuring that weight counts still reasonably correspond to data point counts. Note that weighted data points may not be supported for all types of models.

  • use_label_encoding – whether to replace original class labels with 0-based index in sorted list of labels (a.k.a. label encoding), which is required by some sklearn-compatible implementations (particularly xgboost)

with_sklearn_input_transformer(sklearn_input_transformer) sensai.sklearn.sklearn_base.AbstractSkLearnVectorClassificationModel
Parameters

sklearn_input_transformer – an optional sklearn preprocessor for transforming inputs

Returns

self

get_params(deep=True)
set_params(**params)
class FeatureImportanceProviderSkLearnRegressionMultipleOneDim[source]

Bases: sensai.feature_importance.FeatureImportanceProvider

get_feature_importance_dict() Dict[str, Dict[str, int]]

Gets the feature importance values

Returns

either a dictionary mapping feature names to importance values or (for models predicting multiple variables (independently)) a dictionary which maps predicted variable names to such dictionaries

class FeatureImportanceProviderSkLearnRegressionMultiDim[source]

Bases: sensai.feature_importance.FeatureImportanceProvider

get_feature_importance_dict() Dict[str, float]

Gets the feature importance values

Returns

either a dictionary mapping feature names to importance values or (for models predicting multiple variables (independently)) a dictionary which maps predicted variable names to such dictionaries

class FeatureImportanceProviderSkLearnClassification[source]

Bases: sensai.feature_importance.FeatureImportanceProvider

get_feature_importance_dict() Dict[str, float]

Gets the feature importance values

Returns

either a dictionary mapping feature names to importance values or (for models predicting multiple variables (independently)) a dictionary which maps predicted variable names to such dictionaries