module mlmodel.anmf_predictor
#
Short summary#
module mlinsights.mlmodel.anmf_predictor
Featurizers for machine learned models.
Classes#
class |
truncated documentation |
---|---|
Converts sklearn.decomposition.NMF into a predictor so that the prediction does not involve training even … |
Properties#
property |
truncated documentation |
---|---|
|
HTML representation of estimator. This is redundant with the logic of _repr_mimebundle_. The latter should … |
Static Methods#
staticmethod |
truncated documentation |
---|---|
Returns the list of parameters of the estimator. |
Methods#
method |
truncated documentation |
---|---|
kwargs should contains parameters for sklearn.decomposition.NMF. The parameter force_positive … |
|
Trains a sklearn.decomposition.NMF then a multi-output regressor. |
|
Returns the parameters of the estimator as a dictionary. |
|
Predicts based on the multi-output regressor. The output has the same dimension as X. |
Documentation#
Featurizers for machine learned models.
- 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 ]]
kwargs should contains parameters for sklearn.decomposition.NMF. The parameter force_positive removes all negative predictions and replaces by zero.
- __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.
- classmethod _get_param_names()#
Returns the list of parameters of the estimator.
- fit(X, y=None)#
Trains a sklearn.decomposition.NMF then a multi-output regressor.
- get_params(deep=True)#
Returns the parameters of the estimator as a dictionary.
- predict(X)#
Predicts based on the multi-output regressor. The output has the same dimension as X.