module mlmodel.anmf_predictor#

Inheritance diagram of mlinsights.mlmodel.anmf_predictor

Short summary#

module mlinsights.mlmodel.anmf_predictor

Featurizers for machine learned models.

source on GitHub

Classes#

class

truncated documentation

ApproximateNMFPredictor

Converts sklearn.decomposition.NMF into a predictor so that the prediction does not involve training even …

Properties#

property

truncated documentation

_repr_html_

HTML representation of estimator. This is redundant with the logic of _repr_mimebundle_. The latter should …

Static Methods#

staticmethod

truncated documentation

_get_param_names

Returns the list of parameters of the estimator.

Methods#

method

truncated documentation

__init__

kwargs should contains parameters for sklearn.decomposition.NMF. The parameter force_positive

fit

Trains a sklearn.decomposition.NMF then a multi-output regressor.

get_params

Returns the parameters of the estimator as a dictionary.

predict

Predicts based on the multi-output regressor. The output has the same dimension as X.

Documentation#

Featurizers for machine learned models.

source on GitHub

class mlinsights.mlmodel.anmf_predictor.ApproximateNMFPredictor(force_positive=False, **kwargs)#

Bases: BaseEstimator, RegressorMixin, MultiOutputMixin

Converts sklearn.decomposition.NMF into a predictor so that the prediction does not involve training even for new observations. The class uses a sklearn.decomposition.TruncatedSVD of the components found by the sklearn.decomposition.NMF. The prediction projects the test data into the components vector space and retrieves them back into their original space. The issue is it does not necessarily produce results with only positive results as the sklearn.decomposition.NMF would do unless parameter force_positive is True.

<<<

import numpy
from mlinsights.mlmodel.anmf_predictor import ApproximateNMFPredictor

train = numpy.array([[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0],
                     [1, 0, 0, 0], [1, 0, 0, 0]], dtype=numpy.float64)
train[:train.shape[1], :] += numpy.identity(train.shape[1])

model = ApproximateNMFPredictor(n_components=2,
                                force_positive=True)
model .fit(train)

test = numpy.array([[1, 1, 1, 0]], dtype=numpy.float64)
pred = model.predict(test)
print(pred)

>>>

    [[1.155 0.05  0.84  0.05 ]]

source on GitHub

kwargs should contains parameters for sklearn.decomposition.NMF. The parameter force_positive removes all negative predictions and replaces by zero.

source on GitHub

__init__(force_positive=False, **kwargs)#

kwargs should contains parameters for sklearn.decomposition.NMF. The parameter force_positive removes all negative predictions and replaces by zero.

source on GitHub

classmethod _get_param_names()#

Returns the list of parameters of the estimator.

source on GitHub

fit(X, y=None)#

Trains a sklearn.decomposition.NMF then a multi-output regressor.

source on GitHub

get_params(deep=True)#

Returns the parameters of the estimator as a dictionary.

source on GitHub

predict(X)#

Predicts based on the multi-output regressor. The output has the same dimension as X.

source on GitHub