module mlmodel.ml_featurizer

Inheritance diagram of mlinsights.mlmodel.ml_featurizer

Short summary

module mlinsights.mlmodel.ml_featurizer

Featurizers for machine learned models.

source on GitHub

Classes

class

truncated documentation

FeaturizerTypeError

Unable to process a type.

Functions

function

truncated documentation

is_vector

Tells if X is a vector.

model_featurizer

Converts a machine learned model into a function which converts a vector into features produced by the model. It …

model_featurizer_keras

Builds a featurizer from a keras model It returns a function which returns the output of one particular …

model_featurizer_lr

Builds a featurizer from a :epkg:`scikit-learn:linear_model:LogisticRegression`. It returns a function which returns …

model_featurizer_rfc

Builds a featurizer from a :epkg:`scikit-learn:ensemble:RandomForestClassifier`. It returns a function which returns …

model_featurizer_torch

Builds a featurizer from a torch model It returns a function which returns the output of one particular …

wrap_predict_keras

Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output …

wrap_predict_sklearn

Checks types and dimension. Calls fct and returns the approriate type. A vector if X is a vector, the raw output …

wrap_predict_torch

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.

source on GitHub

exception mlinsights.mlmodel.ml_featurizer.FeaturizerTypeError[source]

Bases: TypeError

Unable to process a type.

source on GitHub

mlinsights.mlmodel.ml_featurizer.is_vector(X)[source]

Tells if X is a vector.

Parameters

X – vector

Returns

boolean

source on GitHub

mlinsights.mlmodel.ml_featurizer.model_featurizer(model, **params)[source]

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

source on GitHub

mlinsights.mlmodel.ml_featurizer.model_featurizer_keras(model, layer=None)[source]

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.

source on GitHub

mlinsights.mlmodel.ml_featurizer.model_featurizer_lr(model)[source]

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

source on GitHub

mlinsights.mlmodel.ml_featurizer.model_featurizer_rfc(model, output=True)[source]

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

source on GitHub

mlinsights.mlmodel.ml_featurizer.model_featurizer_torch(model, layer=None)[source]

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

source on GitHub

mlinsights.mlmodel.ml_featurizer.wrap_predict_keras(X, fct, many, shapes)[source]

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

source on GitHub

mlinsights.mlmodel.ml_featurizer.wrap_predict_sklearn(X, fct, many)[source]

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

source on GitHub

mlinsights.mlmodel.ml_featurizer.wrap_predict_torch(X, fct, many, shapes)[source]

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

source on GitHub