swectral.modelcombiners.regressor_to_classifier#
- swectral.modelcombiners.regressor_to_classifier(regressor, proba_func='softmax', name=None)[source]#
Create a classifier from a numpy-style regressor using one-hot encoding and probability regression.
- Parameters:
- regressor
object A regressor implementing
fit(X, y)andpredict(X).- proba_func
strorCallable,optional Function to convert raw regressor outputs to probabilities. Choose between:
'softmax': row-wise softmax for single-label, mutually exclusive classes'sigmoid': per-class sigmoid for multi-label problemsCallable : a custom probability function.
Default is
'softmax'.- name
strorNone,optional Name of the created model class. If None, the class name is
'<RegressorClassName>Classifier'. Default is None.
- regressor
- Returns:
objectAn numpy-style classifier instance.
- Return type:
See also
Examples
>>> import numpy as np >>> from sklearn.linear_model import LinearRegression >>> X = np.array([[1], [2], [3], [4]]) >>> y = np.array([0, 1, 0, 1])
>>> reg = LinearRegression()
>>> clf = regressor_to_classifier(regressor=reg, proba_func='softmax') >>> clf.fit(X, y)
>>> clf.predict(X)
>>> clf.predict_proba(X)