module mlmodel.ml_featurizer
#
Short summary#
module mlinsights.mlmodel.ml_featurizer
Featurizers for machine learned models.
Classes#
class |
truncated documentation |
---|---|
Unable to process a type. |
Functions#
function |
truncated documentation |
---|---|
Tells if X is a vector. |
|
Converts a machine learned model into a function which converts a vector into features produced by the model. It … |
|
Builds a featurizer from a keras model It returns a function which returns the output of one particular … |
|
Builds a featurizer from a :epkg:`scikit-learn:linear_model:LogisticRegression`. It returns a function which returns … |
|
Builds a featurizer from a :epkg:`scikit-learn:ensemble:RandomForestClassifier`. It returns a function which returns … |
|
Builds a featurizer from a torch model It returns a function which returns the output of one particular … |
|
Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output … |
|
Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output … |
|
Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output … |
Documentation#
Featurizers for machine learned models.
- exception mlinsights.mlmodel.ml_featurizer.FeaturizerTypeError#
Bases:
TypeError
Unable to process a type.
- mlinsights.mlmodel.ml_featurizer.is_vector(X)#
Tells if X is a vector.
- Parameters:
X – vector
- Returns:
boolean
- mlinsights.mlmodel.ml_featurizer.model_featurizer(model, **params)#
Converts a machine learned model into a function which converts a vector into features produced by the model. It can be the output itself or intermediate results. The model can come from scikit-learn, keras or torch.
- Parameters:
model – model
params – additional parameters
- Returns:
function
- mlinsights.mlmodel.ml_featurizer.model_featurizer_keras(model, layer=None)#
Builds a featurizer from a keras model It returns a function which returns the output of one particular layer.
- Parameters:
model – model to use to featurize a vector
layer – number of layers to keep
- Returns:
function
See About Keras models.
- mlinsights.mlmodel.ml_featurizer.model_featurizer_lr(model)#
Builds a featurizer from a :epkg:`scikit-learn:linear_model:LogisticRegression`. It returns a function which returns
model.decision_function(X)
.- Parameters:
model – model to use to featurize a vector
- Returns:
function
- mlinsights.mlmodel.ml_featurizer.model_featurizer_rfc(model, output=True)#
Builds a featurizer from a :epkg:`scikit-learn:ensemble:RandomForestClassifier`. It returns a function which returns the output of every tree (method apply).
- Parameters:
model – model to use to featurize a vector
output – use output (
model.predict_proba(X)
) or trees output (model.apply(X)
)
- Returns:
function
- mlinsights.mlmodel.ml_featurizer.model_featurizer_torch(model, layer=None)#
Builds a featurizer from a torch model It returns a function which returns the output of one particular layer.
- Parameters:
model – model to use to featurize a vector
layer – number of layers to keep
- Returns:
function
- mlinsights.mlmodel.ml_featurizer.wrap_predict_keras(X, fct, many, shapes)#
Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output otherwise.
- Parameters:
X – vector or list
fct – function
many – many observations or just one
shapes – expected input shapes for the neural network
- mlinsights.mlmodel.ml_featurizer.wrap_predict_sklearn(X, fct, many)#
Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output otherwise.
- Parameters:
X – vector or list
fct – function
many – many observations or just one
- mlinsights.mlmodel.ml_featurizer.wrap_predict_torch(X, fct, many, shapes)#
Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output otherwise.
- Parameters:
X – vector or list
fct – function
many – many observations or just one
shapes – expected input shapes for the neural network