sklearn_base#
Source code: sensai/sklearn/sklearn_base.py
- 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:
VectorRegressionModel
,ABC
Base class for models built upon scikit-learn’s model implementations
- Parameters:
model_constructor – the sklearn model constructor
model_args – arguments to be passed to the sklearn model constructor
- log = <Logger sensai.sklearn.sklearn_base.AbstractSkLearnVectorRegressionModel (WARNING)>#
- with_sklearn_input_transformer(sklearn_input_transformer) AbstractSkLearnVectorRegressionModel [source]#
- Parameters:
sklearn_input_transformer – an optional sklearn preprocessor for normalising/scaling inputs
- Returns:
self
- class AbstractSkLearnMultipleOneDimVectorRegressionModel(model_constructor, **model_args)[source]#
Bases:
AbstractSkLearnVectorRegressionModel
,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)
- Parameters:
model_constructor – the sklearn model constructor
model_args – arguments to be passed to the sklearn model constructor
- class AbstractSkLearnMultiDimVectorRegressionModel(model_constructor, **model_args)[source]#
Bases:
AbstractSkLearnVectorRegressionModel
,ABC
Base class for models which use a single sklearn model with multiple output dimensions to create the multi-dimensional model
- 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:
VectorClassificationModel
,ABC
- 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) AbstractSkLearnVectorClassificationModel [source]#
- Parameters:
sklearn_input_transformer – an optional sklearn preprocessor for transforming inputs
- Returns:
self
- class FeatureImportanceProviderSkLearnRegressionMultipleOneDim[source]#
Bases:
FeatureImportanceProvider
- get_feature_importance_dict() Dict[str, Dict[str, int]] [source]#
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:
FeatureImportanceProvider
- class FeatureImportanceProviderSkLearnClassification[source]#
Bases:
FeatureImportanceProvider