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:
regressorobject

A regressor implementing fit(X, y) and predict(X).

proba_funcstr or Callable, 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 problems

  • Callable : a custom probability function.

Default is 'softmax'.

namestr or None, optional

Name of the created model class. If None, the class name is '<RegressorClassName>Classifier'. Default is None.

Returns:
object

An numpy-style classifier instance.

Return type:

object

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)