HROCH

Symbolic regression and classification library

License: MIT PyPI version Downloads CodeQL Unittests pages-build-deploymentUpload Python Package

High-Performance python symbolic regression library based on parallel local search

  • Zero hyperparameter tunning.
  • Accurate results in seconds or minutes, in contrast to slow GP-based methods.
  • Small models size.
  • Support for regression, classification and fuzzy math.
  • Support 32 and 64 bit floating point arithmetic.
  • Work with unprotected version of math operators (log, sqrt, division)
  • Speedup search by using feature importances computed from bbox model
Supported instructions
math add, sub, mul, div, pdiv, inv, minv, sq2, pow, exp, log, sqrt, cbrt, aq
goniometric sin, cos, tan, asin, acos, atan, sinh, cosh, tanh
other nop, max, min, abs, floor, ceil, lt, gt, lte, gte
fuzzy f_and, f_or, f_xor, f_impl, f_not, f_nand, f_nor, f_nxor, f_nimpl

Sources

C++20 source code available in separate repo sr_core

Dependencies

  • AVX2 instructions set(all modern CPU support this)
  • numpy
  • sklearn

Installation

pip install HROCH

Usage

Symbolic_Regression_Demo.ipynb Colab

Documentation

from HROCH import SymbolicRegressor

reg = SymbolicRegressor(num_threads=8, time_limit=60.0, problem='math', precision='f64')
reg.fit(X_train, y_train)
yp = reg.predict(X_test)

Changelog

v1.4

  • sklearn compatibility
  • Classificators:
    • NonlinearLogisticRegressor for a binary classification
    • SymbolicClassifier for multiclass classification
    • FuzzyRegressor for a special binary classification

Older versions

v1.3

  • Public c++ sources
  • Commanline interface changed to cpython
  • Support for classification score logloss and accuracy
  • Support for final transformations:
    • ordinal regression
    • logistic function
    • clipping
  • Acess to equations from all paralel hillclimbers
  • User defined constants

v1.2

  • Features probability as input parameter
  • Custom instructions set
  • Parallel hilclimbing parameters

v1.1

  • Improved late acceptance hillclimbing

v1.0

  • First release

SRBench

full results

SRBench

 1"""
 2.. include:: ../README.md
 3"""
 4from .hroch import RegressorMathModel, ClassifierMathModel
 5from .regressor import SymbolicRegressor
 6from .fuzzy import FuzzyRegressor, FuzzyClassifier
 7from .classifier import NonlinearLogisticRegressor, SymbolicClassifier
 8from .version import __version__
 9
10__all__ = ['SymbolicRegressor','NonlinearLogisticRegressor','SymbolicClassifier','FuzzyRegressor', 'FuzzyClassifier','RegressorMathModel','ClassifierMathModel', '__version__']
class SymbolicRegressor(HROCH.hroch.SymbolicSolver, sklearn.base.RegressorMixin):
  8class SymbolicRegressor(SymbolicSolver, RegressorMixin):
  9    """
 10    SymbolicRegressor class
 11
 12    Parameters
 13    ----------
 14    num_threads : int, default=1
 15        Number of used threads.
 16
 17    time_limit : float, default=5.0
 18        Timeout in seconds. If is set to 0 there is no limit and the algorithm runs until iter_limit is met.
 19
 20    iter_limit : int, default=0
 21        Iterations limit. If is set to 0 there is no limit and the algorithm runs until time_limit is met.
 22
 23    precision : str, default='f32'
 24        'f64' or 'f32'. Internal floating number representation.
 25
 26    problem : str or dict, default='math'
 27        Predefined instructions sets 'math' or 'simple' or 'fuzzy' or custom defines set of instructions with mutation probability.
 28        ```python
 29        problem={'add':10.0, 'mul':10.0, 'gt':1.0, 'lt':1.0, 'nop':1.0}
 30        ```
 31
 32        |**supported instructions**||
 33        |-|-|
 34        |**math**|add, sub, mul, div, pdiv, inv, minv, sq2, pow, exp, log, sqrt, cbrt, aq|
 35        |**goniometric**|sin, cos, tan, asin, acos, atan, sinh, cosh, tanh|
 36        |**other**|nop, max, min, abs, floor, ceil, lt, gt, lte, gte|
 37        |**fuzzy**|f_and, f_or, f_xor, f_impl, f_not, f_nand, f_nor, f_nxor, f_nimpl|
 38
 39        *nop - no operation*
 40
 41        *pdiv - protected division*
 42
 43        *inv - inverse* $(-x)$
 44
 45        *minv - multiplicative inverse* $(1/x)$
 46
 47        *lt, gt, lte, gte -* $<, >, <=, >=$
 48
 49    feature_probs : array of shape (n_features,), default=None
 50        The probability that a mutation will select a feature.
 51
 52    random_state : int, default=0
 53        Random generator seed. If 0 then random generator will be initialized by system time.
 54
 55    verbose : int, default=0
 56        Controls the verbosity when fitting and predicting.
 57
 58    metric : str, default='MSE'
 59            Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'}
 60
 61    transformation : str, default=None
 62        Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'}
 63
 64    algo_settings : dict, default = None
 65        If not defined SymbolicSolver.ALGO_SETTINGS is used.
 66        ```python
 67        algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16}
 68        ```
 69        - 'neighbours_count' : (int) Number tested neighbours in each iteration
 70        - 'alpha' : (float) Score worsening limit for a iteration
 71        - 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1
 72        - 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating
 73        - 'sample_size : (int) Number of batches of sample used to calculate the score during training
 74
 75    code_settings : dict, default = None
 76        If not defined SymbolicSolver.CODE_SETTINGS is used.
 77        ```python
 78        code_settings = {'min_size': 32, 'max_size':32, 'const_size':8}
 79        ```
 80        - 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0.
 81        - 'min_size': (int) Minimum allowed equation size(as a linear program).
 82        - 'max_size' : (int) Maximum allowed equation size(as a linear program).
 83        
 84    population_settings : dict, default = None
 85        If not defined SymbolicSolver.POPULATION_SETTINGS is used.
 86        ```python
 87        population_settings = {'size': 64, 'tournament':4}
 88        ```
 89        - 'size' : (int) Number of individuals in the population.
 90        - 'tournament' : (int) Tournament selection.
 91
 92    init_const_settings : dict, default = None
 93        If not defined SymbolicSolver.INIT_CONST_SETTINGS is used.
 94        ```python
 95        init_const_settings = {'const_min':-1.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
 96        ```
 97        - 'const_min' : (float) Lower range for initializing constants.
 98        - 'const_max' : (float) Upper range for initializing constants.
 99        - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization.
100        - 'predefined_const_set' : (array of floats) Predefined constants used during initialization.
101
102    const_settings : dict, default = None
103        If not defined SymbolicSolver.CONST_SETTINGS is used.
104        ```python
105        const_settings = {'const_min':-LARGE_FLOAT, 'const_max':LARGE_FLOAT, 'predefined_const_prob':0.0, 'predefined_const_set': []}
106        ```
107        - 'const_min' : (float) Lower range for constants used in equations.
108        - 'const_max' : (float) Upper range for constants used in equations.
109        - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation).
110        - 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation).
111
112    target_clip : array of two float values clip_min and clip_max, default None
113        ```python
114        target_clip=[-1, 1]
115        ```
116
117    cv_params : dict, default = None
118        If not defined SymbolicSolver.REGRESSION_CV_PARAMS is used
119        ```python
120        cv_params = {'n':0, 'cv_params':{}, 'select':'mean', 'opt_params':{'method': 'Nelder-Mead'}, 'opt_metric':make_scorer(mean_squared_error, greater_is_better=False)}
121        ```
122        - 'n' : (int) Crossvalidate n top models
123        - 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method
124        - select : (str) Best model selection method choose from 'mean'or 'median'
125        - opt_params : (dict) Parameters passed to scipy.optimize.minimize method
126        - opt_metric : (make_scorer) Scoring method
127        
128    warm_start : bool, default=False
129        If True, then the solver will be reused for the next call of fit.
130    """
131
132    def __init__(self,
133                 num_threads: int = 1,
134                 time_limit: float = 5.0,
135                 iter_limit: int = 0,
136                 precision: str = 'f32',
137                 problem = 'math',
138                 feature_probs = None,
139                 random_state: int = 0,
140                 verbose: int = 0,
141                 metric: str = 'MSE',
142                 transformation: str = None,
143                 algo_settings = None,
144                 code_settings = None,
145                 population_settings = None,
146                 init_const_settings = None,
147                 const_settings = None,
148                 target_clip: Iterable = None,
149                 cv_params = None,
150                 warm_start : bool = False
151                 ):
152        super(SymbolicRegressor, self).__init__(
153            num_threads=num_threads,
154            time_limit=time_limit,
155            iter_limit=iter_limit,
156            precision=precision,
157            problem=problem,
158            feature_probs=feature_probs,
159            random_state=random_state,
160            verbose=verbose,
161            metric=metric,
162            transformation=transformation,
163            algo_settings=algo_settings,
164            code_settings=code_settings,
165            population_settings=population_settings,
166            init_const_settings=init_const_settings,
167            const_settings=const_settings,
168            target_clip=target_clip,
169            class_weight=None,
170            cv_params=cv_params,
171            warm_start=warm_start
172        )
173
174    def fit(self, X, y, sample_weight=None, check_input=True):
175        """
176        Fit the symbolic models according to the given training data. 
177
178        Parameters
179        ----------
180        X : array-like of shape (n_samples, n_features)
181            Training vector, where `n_samples` is the number of samples and
182            `n_features` is the number of features.
183
184        y : array-like of shape (n_samples,)
185            Target vector relative to X.
186
187        sample_weight : array-like of shape (n_samples,) default=None
188            Array of weights that are assigned to individual samples.
189            If not provided, then each sample is given unit weight.
190
191        check_input : bool, default=True
192            Allow to bypass several input checking.
193            Don't use this parameter unless you know what you're doing.
194
195        Returns
196        -------
197        self
198            Fitted estimator.
199        """
200
201        super(SymbolicRegressor, self).fit(X, y, sample_weight=sample_weight, check_input=check_input)
202        return self
203    
204    def predict(self, X, id=None, check_input=True, use_parsed_model=True):
205        """
206        Predict regression target for X.
207
208        Parameters
209        ----------
210        X : array-like of shape (n_samples, n_features)
211            The input samples.
212
213        id : int
214            Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
215
216        check_input : bool, default=True
217            Allow to bypass several input checking.
218            Don't use this parameter unless you know what you're doing.
219
220        Returns
221        -------
222        y : ndarray of shape (n_samples,) or (n_samples, n_outputs)
223            The predicted values.
224        """
225        return super(SymbolicRegressor, self).predict(X, id=id, check_input=check_input, use_parsed_model=use_parsed_model)

SymbolicRegressor class

Parameters
  • num_threads (int, default=1): Number of used threads.
  • time_limit (float, default=5.0): Timeout in seconds. If is set to 0 there is no limit and the algorithm runs until iter_limit is met.
  • iter_limit (int, default=0): Iterations limit. If is set to 0 there is no limit and the algorithm runs until time_limit is met.
  • precision (str, default='f32'): 'f64' or 'f32'. Internal floating number representation.
  • problem (str or dict, default='math'): Predefined instructions sets 'math' or 'simple' or 'fuzzy' or custom defines set of instructions with mutation probability.

    problem={'add':10.0, 'mul':10.0, 'gt':1.0, 'lt':1.0, 'nop':1.0}
    
    supported instructions
    math add, sub, mul, div, pdiv, inv, minv, sq2, pow, exp, log, sqrt, cbrt, aq
    goniometric sin, cos, tan, asin, acos, atan, sinh, cosh, tanh
    other nop, max, min, abs, floor, ceil, lt, gt, lte, gte
    fuzzy f_and, f_or, f_xor, f_impl, f_not, f_nand, f_nor, f_nxor, f_nimpl

    nop - no operation

    pdiv - protected division

    inv - inverse $(-x)$

    minv - multiplicative inverse $(1/x)$

    lt, gt, lte, gte - $<, >, <=, >=$

  • feature_probs (array of shape (n_features,), default=None): The probability that a mutation will select a feature.
  • random_state (int, default=0): Random generator seed. If 0 then random generator will be initialized by system time.
  • verbose (int, default=0): Controls the verbosity when fitting and predicting.
  • metric (str, default='MSE'): Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'}
  • transformation (str, default=None): Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'}
  • algo_settings (dict, default = None): If not defined SymbolicSolver.ALGO_SETTINGS is used.

    algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16}
    
    • 'neighbours_count' : (int) Number tested neighbours in each iteration
    • 'alpha' : (float) Score worsening limit for a iteration
    • 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1
    • 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating
    • 'sample_size : (int) Number of batches of sample used to calculate the score during training
  • code_settings (dict, default = None): If not defined SymbolicSolver.CODE_SETTINGS is used.

    code_settings = {'min_size': 32, 'max_size':32, 'const_size':8}
    
    • 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0.
    • 'min_size': (int) Minimum allowed equation size(as a linear program).
    • 'max_size' : (int) Maximum allowed equation size(as a linear program).
  • population_settings (dict, default = None): If not defined SymbolicSolver.POPULATION_SETTINGS is used.

    population_settings = {'size': 64, 'tournament':4}
    
    • 'size' : (int) Number of individuals in the population.
    • 'tournament' : (int) Tournament selection.
  • init_const_settings (dict, default = None): If not defined SymbolicSolver.INIT_CONST_SETTINGS is used.

    init_const_settings = {'const_min':-1.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
    
    • 'const_min' : (float) Lower range for initializing constants.
    • 'const_max' : (float) Upper range for initializing constants.
    • 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization.
    • 'predefined_const_set' : (array of floats) Predefined constants used during initialization.
  • const_settings (dict, default = None): If not defined SymbolicSolver.CONST_SETTINGS is used.

    const_settings = {'const_min':-LARGE_FLOAT, 'const_max':LARGE_FLOAT, 'predefined_const_prob':0.0, 'predefined_const_set': []}
    
    • 'const_min' : (float) Lower range for constants used in equations.
    • 'const_max' : (float) Upper range for constants used in equations.
    • 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation).
    • 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation).
  • target_clip (array of two float values clip_min and clip_max, default None):

    target_clip=[-1, 1]
    
  • cv_params (dict, default = None): If not defined SymbolicSolver.REGRESSION_CV_PARAMS is used

    cv_params = {'n':0, 'cv_params':{}, 'select':'mean', 'opt_params':{'method': 'Nelder-Mead'}, 'opt_metric':make_scorer(mean_squared_error, greater_is_better=False)}
    
    • 'n' : (int) Crossvalidate n top models
    • 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method
    • select : (str) Best model selection method choose from 'mean'or 'median'
    • opt_params : (dict) Parameters passed to scipy.optimize.minimize method
    • opt_metric : (make_scorer) Scoring method
  • warm_start (bool, default=False): If True, then the solver will be reused for the next call of fit.
SymbolicRegressor( num_threads: int = 1, time_limit: float = 5.0, iter_limit: int = 0, precision: str = 'f32', problem='math', feature_probs=None, random_state: int = 0, verbose: int = 0, metric: str = 'MSE', transformation: str = None, algo_settings=None, code_settings=None, population_settings=None, init_const_settings=None, const_settings=None, target_clip: Iterable = None, cv_params=None, warm_start: bool = False)
132    def __init__(self,
133                 num_threads: int = 1,
134                 time_limit: float = 5.0,
135                 iter_limit: int = 0,
136                 precision: str = 'f32',
137                 problem = 'math',
138                 feature_probs = None,
139                 random_state: int = 0,
140                 verbose: int = 0,
141                 metric: str = 'MSE',
142                 transformation: str = None,
143                 algo_settings = None,
144                 code_settings = None,
145                 population_settings = None,
146                 init_const_settings = None,
147                 const_settings = None,
148                 target_clip: Iterable = None,
149                 cv_params = None,
150                 warm_start : bool = False
151                 ):
152        super(SymbolicRegressor, self).__init__(
153            num_threads=num_threads,
154            time_limit=time_limit,
155            iter_limit=iter_limit,
156            precision=precision,
157            problem=problem,
158            feature_probs=feature_probs,
159            random_state=random_state,
160            verbose=verbose,
161            metric=metric,
162            transformation=transformation,
163            algo_settings=algo_settings,
164            code_settings=code_settings,
165            population_settings=population_settings,
166            init_const_settings=init_const_settings,
167            const_settings=const_settings,
168            target_clip=target_clip,
169            class_weight=None,
170            cv_params=cv_params,
171            warm_start=warm_start
172        )
def fit(self, X, y, sample_weight=None, check_input=True):
174    def fit(self, X, y, sample_weight=None, check_input=True):
175        """
176        Fit the symbolic models according to the given training data. 
177
178        Parameters
179        ----------
180        X : array-like of shape (n_samples, n_features)
181            Training vector, where `n_samples` is the number of samples and
182            `n_features` is the number of features.
183
184        y : array-like of shape (n_samples,)
185            Target vector relative to X.
186
187        sample_weight : array-like of shape (n_samples,) default=None
188            Array of weights that are assigned to individual samples.
189            If not provided, then each sample is given unit weight.
190
191        check_input : bool, default=True
192            Allow to bypass several input checking.
193            Don't use this parameter unless you know what you're doing.
194
195        Returns
196        -------
197        self
198            Fitted estimator.
199        """
200
201        super(SymbolicRegressor, self).fit(X, y, sample_weight=sample_weight, check_input=check_input)
202        return self

Fit the symbolic models according to the given training data.

Parameters
  • X (array-like of shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features.
  • y (array-like of shape (n_samples,)): Target vector relative to X.
  • sample_weight (array-like of shape (n_samples,) default=None): Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • self: Fitted estimator.
def predict(self, X, id=None, check_input=True, use_parsed_model=True):
204    def predict(self, X, id=None, check_input=True, use_parsed_model=True):
205        """
206        Predict regression target for X.
207
208        Parameters
209        ----------
210        X : array-like of shape (n_samples, n_features)
211            The input samples.
212
213        id : int
214            Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
215
216        check_input : bool, default=True
217            Allow to bypass several input checking.
218            Don't use this parameter unless you know what you're doing.
219
220        Returns
221        -------
222        y : ndarray of shape (n_samples,) or (n_samples, n_outputs)
223            The predicted values.
224        """
225        return super(SymbolicRegressor, self).predict(X, id=id, check_input=check_input, use_parsed_model=use_parsed_model)

Predict regression target for X.

Parameters
  • X (array-like of shape (n_samples, n_features)): The input samples.
  • id (int): Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • y (ndarray of shape (n_samples,) or (n_samples, n_outputs)): The predicted values.
def set_fit_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_score_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
Inherited Members
HROCH.hroch.SymbolicSolver
LARGE_FLOAT
SIMPLE
MATH
FUZZY
ALGO_SETTINGS
CODE_SETTINGS
POPULATION_SETTINGS
INIT_CONST_SETTINGS
CONST_SETTINGS
REGRESSION_CV_PARAMS
CLASSIFICATION_CV_PARAMS
REGRESSION_TARGET_CLIP
CLASSIFICATION_TARGET_CLIP
num_threads
time_limit
iter_limit
verbose
precision
problem
feature_probs
random_state
code_settings
population_settings
metric
transformation
algo_settings
init_const_settings
const_settings
target_clip
class_weight
cv_params
warm_start
equation
get_models
sklearn.base.BaseEstimator
get_params
set_params
sklearn.utils._metadata_requests._MetadataRequester
get_metadata_routing
sklearn.base.RegressorMixin
score
class NonlinearLogisticRegressor(HROCH.hroch.SymbolicSolver, sklearn.base.ClassifierMixin):
 11class NonlinearLogisticRegressor(SymbolicSolver, ClassifierMixin):
 12    """
 13    Nonlinear Logistic Regressor
 14
 15    Parameters
 16    ----------
 17    num_threads : int, default=1
 18        Number of used threads.
 19
 20    time_limit : float, default=5.0
 21        Timeout in seconds. If is set to 0 there is no limit and the algorithm runs until iter_limit is met.
 22
 23    iter_limit : int, default=0
 24        Iterations limit. If is set to 0 there is no limit and the algorithm runs until time_limit is met.
 25
 26    precision : str, default='f32'
 27        'f64' or 'f32'. Internal floating number representation.
 28
 29    problem : str or dict, default='math'
 30        Predefined instructions sets 'math' or 'simple' or 'fuzzy' or custom defines set of instructions with mutation probability.
 31        ```python
 32        problem={'add':10.0, 'mul':10.0, 'gt':1.0, 'lt':1.0, 'nop':1.0}
 33        ```
 34
 35        |**supported instructions**||
 36        |-|-|
 37        |**math**|add, sub, mul, div, pdiv, inv, minv, sq2, pow, exp, log, sqrt, cbrt, aq|
 38        |**goniometric**|sin, cos, tan, asin, acos, atan, sinh, cosh, tanh|
 39        |**other**|nop, max, min, abs, floor, ceil, lt, gt, lte, gte|
 40        |**fuzzy**|f_and, f_or, f_xor, f_impl, f_not, f_nand, f_nor, f_nxor, f_nimpl|
 41
 42        *nop - no operation*
 43
 44        *pdiv - protected division*
 45
 46        *inv - inverse* $(-x)$
 47
 48        *minv - multiplicative inverse* $(1/x)$
 49
 50        *lt, gt, lte, gte -* $<, >, <=, >=$
 51
 52    feature_probs : array of shape (n_features,), default=None
 53        The probability that a mutation will select a feature.
 54
 55    random_state : int, default=0
 56        Random generator seed. If 0 then random generator will be initialized by system time.
 57
 58    verbose : int, default=0
 59        Controls the verbosity when fitting and predicting.
 60
 61    metric : str, default='LogLoss'
 62        Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'}
 63
 64    transformation : str, default='LOGISTIC'
 65        Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'}
 66
 67    algo_settings : dict, default = None
 68        If not defined SymbolicSolver.ALGO_SETTINGS is used.
 69        ```python
 70        algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16}
 71        ```
 72        - 'neighbours_count' : (int) Number tested neighbours in each iteration
 73        - 'alpha' : (float) Score worsening limit for a iteration
 74        - 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1
 75        - 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating
 76        - 'sample_size : (int) Number of batches of sample used to calculate the score during training
 77
 78    code_settings : dict, default = None
 79        If not defined SymbolicSolver.CODE_SETTINGS is used.
 80        ```python
 81        code_settings = {'min_size': 32, 'max_size':32, 'const_size':8}
 82        ```
 83        - 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0.
 84        - 'min_size': (int) Minimum allowed equation size(as a linear program).
 85        - 'max_size' : (int) Maximum allowed equation size(as a linear program).
 86        
 87    population_settings : dict, default = None
 88        If not defined SymbolicSolver.POPULATION_SETTINGS is used.
 89        ```python
 90        population_settings = {'size': 64, 'tournament':4}
 91        ```
 92        - 'size' : (int) Number of individuals in the population.
 93        - 'tournament' : (int) Tournament selection.
 94
 95    init_const_settings : dict, default = None
 96        If not defined SymbolicSolver.INIT_CONST_SETTINGS is used.
 97        ```python
 98        init_const_settings = {'const_min':-1.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
 99        ```
100        - 'const_min' : (float) Lower range for initializing constants.
101        - 'const_max' : (float) Upper range for initializing constants.
102        - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization.
103        - 'predefined_const_set' : (array of floats) Predefined constants used during initialization.
104
105    const_settings : dict, default = None
106        If not defined SymbolicSolver.CONST_SETTINGS is used.
107        ```python
108        const_settings = {'const_min':-LARGE_FLOAT, 'const_max':LARGE_FLOAT, 'predefined_const_prob':0.0, 'predefined_const_set': []}
109        ```
110        - 'const_min' : (float) Lower range for constants used in equations.
111        - 'const_max' : (float) Upper range for constants used in equations.
112        - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation).
113        - 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation).
114
115    target_clip : array, default = None
116        Array of two float values clip_min and clip_max.
117        If not defined SymbolicSolver.CLASSIFICATION_TARGET_CLIP is used.
118        ```python
119        target_clip=[3e-7, 1.0-3e-7]
120        ```
121    class_weight : dict or 'balanced', default=None
122        Weights associated with classes in the form ``{class_label: weight}``.
123        If not given, all classes are supposed to have weight one.
124
125        The "balanced" mode uses the values of y to automatically adjust
126        weights inversely proportional to class frequencies in the input data
127        as ``n_samples / (n_classes * np.bincount(y))``.
128
129        Note that these weights will be multiplied with sample_weight (passed
130        through the fit method) if sample_weight is specified.
131
132    cv_params : dict, default = None
133        If not defined SymbolicSolver.CLASSIFICATION_CV_PARAMS is used.
134        ```python
135        cv_params = {'n':0, 'cv_params':{}, 'select':'mean', 'opt_params':{'method': 'Nelder-Mead'}, 'opt_metric':make_scorer(log_loss, greater_is_better=False, needs_proba=True)}
136        ```
137        - 'n' : (int) Crossvalidate n top models
138        - 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method
139        - select : (str) Best model selection method choose from 'mean'or 'median'
140        - opt_params : (dict) Parameters passed to scipy.optimize.minimize method
141        - opt_metric : (make_scorer) Scoring method
142        
143    warm_start : bool, default=False
144        If True, then the solver will be reused for the next call of fit.
145    """
146
147    def __init__(self,
148                 num_threads: int = 1,
149                 time_limit: float = 5.0,
150                 iter_limit: int = 0,
151                 precision: str = 'f32',
152                 problem = 'math',
153                 feature_probs = None,
154                 random_state: int = 0,
155                 verbose: int = 0,
156                 metric: str = 'LogLoss',
157                 transformation: str = 'LOGISTIC',
158                 algo_settings = None,
159                 code_settings = None,
160                 population_settings = None,
161                 init_const_settings = None,
162                 const_settings = None,
163                 target_clip = None,
164                 class_weight = None,
165                 cv_params = None,
166                 warm_start : bool = False
167                 ):
168
169        super(NonlinearLogisticRegressor, self).__init__(
170            num_threads=num_threads,
171            time_limit=time_limit,
172            iter_limit=iter_limit,
173            precision=precision,
174            problem=problem,
175            feature_probs=feature_probs,
176            random_state=random_state,
177            verbose=verbose,
178            metric=metric,
179            transformation=transformation,
180            algo_settings=algo_settings,
181            code_settings=code_settings,
182            population_settings=population_settings,
183            init_const_settings=init_const_settings,
184            const_settings=const_settings,
185            target_clip=target_clip,
186            class_weight=class_weight,
187            cv_params=cv_params,
188            warm_start=warm_start
189        )
190
191    def fit(self, X, y, sample_weight=None, check_input=True):
192        """
193        Fit the symbolic models according to the given training data. 
194
195        Parameters
196        ----------
197        X : array-like of shape (n_samples, n_features)
198            Training vector, where `n_samples` is the number of samples and
199            `n_features` is the number of features.
200
201        y : array-like of shape (n_samples,)
202            Target vector relative to X. Needs samples of 2 classes.
203
204        sample_weight : array-like of shape (n_samples,) default=None
205            Array of weights that are assigned to individual samples.
206            If not provided, then each sample is given unit weight.
207
208        check_input : bool, default=True
209            Allow to bypass several input checking.
210            Don't use this parameter unless you know what you're doing.
211
212        Returns
213        -------
214        self
215            Fitted estimator.
216        """
217        
218        if check_input:
219            X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False)
220        check_classification_targets(y)
221        enc = LabelEncoder()
222        y_ind = enc.fit_transform(y)
223        self.classes_ = enc.classes_
224        self.n_classes_ = len(self.classes_)
225        if self.n_classes_ != 2:
226            raise ValueError(
227                "This solver needs samples of 2 classes"
228                " in the data, but the data contains"
229                " %r classes"
230                % self.n_classes_
231            )
232
233        self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y)
234
235        super(NonlinearLogisticRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=False)
236        return self
237
238    def predict(self, X, id=None, check_input=True, use_parsed_model=True):
239        """
240        Predict class for X.
241
242        Parameters
243        ----------
244        X : array-like of shape (n_samples, n_features)
245            The input samples.
246            
247        id : int
248            Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
249
250        check_input : bool, default=True
251            Allow to bypass several input checking.
252            Don't use this parameter unless you know what you're doing.
253
254        Returns
255        -------
256        y : ndarray of shape (n_samples,)
257            The predicted classes.
258        """
259        preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model)
260        return self.classes_[(preds > 0.5).astype(int)]
261
262    def predict_proba(self, X, id=None, check_input=True):
263        """
264        Predict class probabilities for X.
265
266        Parameters
267        ----------
268        X : array-like of shape (n_samples, n_features)
269
270        check_input : bool, default=True
271            Allow to bypass several input checking.
272            Don't use this parameter unless you know what you're doing.
273
274        Returns
275        -------
276        T : ndarray of shape (n_samples, n_classes)
277            The class probabilities of the input samples. The order of the
278            classes corresponds to that in the attribute :term:`classes_`.
279        """
280        preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input)
281        proba = numpy.vstack([1 - preds, preds]).T
282        return proba
283    
284    def _more_tags(self):
285        return {'binary_only': True}

Nonlinear Logistic Regressor

Parameters
  • num_threads (int, default=1): Number of used threads.
  • time_limit (float, default=5.0): Timeout in seconds. If is set to 0 there is no limit and the algorithm runs until iter_limit is met.
  • iter_limit (int, default=0): Iterations limit. If is set to 0 there is no limit and the algorithm runs until time_limit is met.
  • precision (str, default='f32'): 'f64' or 'f32'. Internal floating number representation.
  • problem (str or dict, default='math'): Predefined instructions sets 'math' or 'simple' or 'fuzzy' or custom defines set of instructions with mutation probability.

    problem={'add':10.0, 'mul':10.0, 'gt':1.0, 'lt':1.0, 'nop':1.0}
    
    supported instructions
    math add, sub, mul, div, pdiv, inv, minv, sq2, pow, exp, log, sqrt, cbrt, aq
    goniometric sin, cos, tan, asin, acos, atan, sinh, cosh, tanh
    other nop, max, min, abs, floor, ceil, lt, gt, lte, gte
    fuzzy f_and, f_or, f_xor, f_impl, f_not, f_nand, f_nor, f_nxor, f_nimpl

    nop - no operation

    pdiv - protected division

    inv - inverse $(-x)$

    minv - multiplicative inverse $(1/x)$

    lt, gt, lte, gte - $<, >, <=, >=$

  • feature_probs (array of shape (n_features,), default=None): The probability that a mutation will select a feature.
  • random_state (int, default=0): Random generator seed. If 0 then random generator will be initialized by system time.
  • verbose (int, default=0): Controls the verbosity when fitting and predicting.
  • metric (str, default='LogLoss'): Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'}
  • transformation (str, default='LOGISTIC'): Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'}
  • algo_settings (dict, default = None): If not defined SymbolicSolver.ALGO_SETTINGS is used.

    algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16}
    
    • 'neighbours_count' : (int) Number tested neighbours in each iteration
    • 'alpha' : (float) Score worsening limit for a iteration
    • 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1
    • 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating
    • 'sample_size : (int) Number of batches of sample used to calculate the score during training
  • code_settings (dict, default = None): If not defined SymbolicSolver.CODE_SETTINGS is used.

    code_settings = {'min_size': 32, 'max_size':32, 'const_size':8}
    
    • 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0.
    • 'min_size': (int) Minimum allowed equation size(as a linear program).
    • 'max_size' : (int) Maximum allowed equation size(as a linear program).
  • population_settings (dict, default = None): If not defined SymbolicSolver.POPULATION_SETTINGS is used.

    population_settings = {'size': 64, 'tournament':4}
    
    • 'size' : (int) Number of individuals in the population.
    • 'tournament' : (int) Tournament selection.
  • init_const_settings (dict, default = None): If not defined SymbolicSolver.INIT_CONST_SETTINGS is used.

    init_const_settings = {'const_min':-1.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
    
    • 'const_min' : (float) Lower range for initializing constants.
    • 'const_max' : (float) Upper range for initializing constants.
    • 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization.
    • 'predefined_const_set' : (array of floats) Predefined constants used during initialization.
  • const_settings (dict, default = None): If not defined SymbolicSolver.CONST_SETTINGS is used.

    const_settings = {'const_min':-LARGE_FLOAT, 'const_max':LARGE_FLOAT, 'predefined_const_prob':0.0, 'predefined_const_set': []}
    
    • 'const_min' : (float) Lower range for constants used in equations.
    • 'const_max' : (float) Upper range for constants used in equations.
    • 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation).
    • 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation).
  • target_clip (array, default = None): Array of two float values clip_min and clip_max. If not defined SymbolicSolver.CLASSIFICATION_TARGET_CLIP is used.

    target_clip=[3e-7, 1.0-3e-7]
    
  • class_weight (dict or 'balanced', default=None): Weights associated with classes in the form {class_label: weight}. If not given, all classes are supposed to have weight one.

    The "balanced" mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y)).

    Note that these weights will be multiplied with sample_weight (passed through the fit method) if sample_weight is specified.

  • cv_params (dict, default = None): If not defined SymbolicSolver.CLASSIFICATION_CV_PARAMS is used.

    cv_params = {'n':0, 'cv_params':{}, 'select':'mean', 'opt_params':{'method': 'Nelder-Mead'}, 'opt_metric':make_scorer(log_loss, greater_is_better=False, needs_proba=True)}
    
    • 'n' : (int) Crossvalidate n top models
    • 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method
    • select : (str) Best model selection method choose from 'mean'or 'median'
    • opt_params : (dict) Parameters passed to scipy.optimize.minimize method
    • opt_metric : (make_scorer) Scoring method
  • warm_start (bool, default=False): If True, then the solver will be reused for the next call of fit.
NonlinearLogisticRegressor( num_threads: int = 1, time_limit: float = 5.0, iter_limit: int = 0, precision: str = 'f32', problem='math', feature_probs=None, random_state: int = 0, verbose: int = 0, metric: str = 'LogLoss', transformation: str = 'LOGISTIC', algo_settings=None, code_settings=None, population_settings=None, init_const_settings=None, const_settings=None, target_clip=None, class_weight=None, cv_params=None, warm_start: bool = False)
147    def __init__(self,
148                 num_threads: int = 1,
149                 time_limit: float = 5.0,
150                 iter_limit: int = 0,
151                 precision: str = 'f32',
152                 problem = 'math',
153                 feature_probs = None,
154                 random_state: int = 0,
155                 verbose: int = 0,
156                 metric: str = 'LogLoss',
157                 transformation: str = 'LOGISTIC',
158                 algo_settings = None,
159                 code_settings = None,
160                 population_settings = None,
161                 init_const_settings = None,
162                 const_settings = None,
163                 target_clip = None,
164                 class_weight = None,
165                 cv_params = None,
166                 warm_start : bool = False
167                 ):
168
169        super(NonlinearLogisticRegressor, self).__init__(
170            num_threads=num_threads,
171            time_limit=time_limit,
172            iter_limit=iter_limit,
173            precision=precision,
174            problem=problem,
175            feature_probs=feature_probs,
176            random_state=random_state,
177            verbose=verbose,
178            metric=metric,
179            transformation=transformation,
180            algo_settings=algo_settings,
181            code_settings=code_settings,
182            population_settings=population_settings,
183            init_const_settings=init_const_settings,
184            const_settings=const_settings,
185            target_clip=target_clip,
186            class_weight=class_weight,
187            cv_params=cv_params,
188            warm_start=warm_start
189        )
def fit(self, X, y, sample_weight=None, check_input=True):
191    def fit(self, X, y, sample_weight=None, check_input=True):
192        """
193        Fit the symbolic models according to the given training data. 
194
195        Parameters
196        ----------
197        X : array-like of shape (n_samples, n_features)
198            Training vector, where `n_samples` is the number of samples and
199            `n_features` is the number of features.
200
201        y : array-like of shape (n_samples,)
202            Target vector relative to X. Needs samples of 2 classes.
203
204        sample_weight : array-like of shape (n_samples,) default=None
205            Array of weights that are assigned to individual samples.
206            If not provided, then each sample is given unit weight.
207
208        check_input : bool, default=True
209            Allow to bypass several input checking.
210            Don't use this parameter unless you know what you're doing.
211
212        Returns
213        -------
214        self
215            Fitted estimator.
216        """
217        
218        if check_input:
219            X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False)
220        check_classification_targets(y)
221        enc = LabelEncoder()
222        y_ind = enc.fit_transform(y)
223        self.classes_ = enc.classes_
224        self.n_classes_ = len(self.classes_)
225        if self.n_classes_ != 2:
226            raise ValueError(
227                "This solver needs samples of 2 classes"
228                " in the data, but the data contains"
229                " %r classes"
230                % self.n_classes_
231            )
232
233        self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y)
234
235        super(NonlinearLogisticRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=False)
236        return self

Fit the symbolic models according to the given training data.

Parameters
  • X (array-like of shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features.
  • y (array-like of shape (n_samples,)): Target vector relative to X. Needs samples of 2 classes.
  • sample_weight (array-like of shape (n_samples,) default=None): Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • self: Fitted estimator.
def predict(self, X, id=None, check_input=True, use_parsed_model=True):
238    def predict(self, X, id=None, check_input=True, use_parsed_model=True):
239        """
240        Predict class for X.
241
242        Parameters
243        ----------
244        X : array-like of shape (n_samples, n_features)
245            The input samples.
246            
247        id : int
248            Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
249
250        check_input : bool, default=True
251            Allow to bypass several input checking.
252            Don't use this parameter unless you know what you're doing.
253
254        Returns
255        -------
256        y : ndarray of shape (n_samples,)
257            The predicted classes.
258        """
259        preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model)
260        return self.classes_[(preds > 0.5).astype(int)]

Predict class for X.

Parameters
  • X (array-like of shape (n_samples, n_features)): The input samples.
  • id (int): Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • y (ndarray of shape (n_samples,)): The predicted classes.
def predict_proba(self, X, id=None, check_input=True):
262    def predict_proba(self, X, id=None, check_input=True):
263        """
264        Predict class probabilities for X.
265
266        Parameters
267        ----------
268        X : array-like of shape (n_samples, n_features)
269
270        check_input : bool, default=True
271            Allow to bypass several input checking.
272            Don't use this parameter unless you know what you're doing.
273
274        Returns
275        -------
276        T : ndarray of shape (n_samples, n_classes)
277            The class probabilities of the input samples. The order of the
278            classes corresponds to that in the attribute :term:`classes_`.
279        """
280        preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input)
281        proba = numpy.vstack([1 - preds, preds]).T
282        return proba

Predict class probabilities for X.

Parameters
  • X (array-like of shape (n_samples, n_features)):

  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.

Returns
  • T (ndarray of shape (n_samples, n_classes)): The class probabilities of the input samples. The order of the classes corresponds to that in the attribute :term:classes_.
def set_fit_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_proba_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_score_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
Inherited Members
HROCH.hroch.SymbolicSolver
LARGE_FLOAT
SIMPLE
MATH
FUZZY
ALGO_SETTINGS
CODE_SETTINGS
POPULATION_SETTINGS
INIT_CONST_SETTINGS
CONST_SETTINGS
REGRESSION_CV_PARAMS
CLASSIFICATION_CV_PARAMS
REGRESSION_TARGET_CLIP
CLASSIFICATION_TARGET_CLIP
num_threads
time_limit
iter_limit
verbose
precision
problem
feature_probs
random_state
code_settings
population_settings
metric
transformation
algo_settings
init_const_settings
const_settings
target_clip
class_weight
cv_params
warm_start
equation
get_models
sklearn.base.BaseEstimator
get_params
set_params
sklearn.utils._metadata_requests._MetadataRequester
get_metadata_routing
sklearn.base.ClassifierMixin
score
class SymbolicClassifier(sklearn.multiclass.OneVsRestClassifier):
287class SymbolicClassifier(OneVsRestClassifier):
288    """
289    OVR multiclass symbolic classificator
290    
291    Parameters
292    ----------
293    estimator : NonlinearLogisticRegressor
294        Instance of NonlinearLogisticRegressor class.
295    """
296    def __init__(self, estimator=NonlinearLogisticRegressor()):
297        super().__init__(estimator=estimator)
298    
299    def fit(self, X, y):
300        """
301        Fit the symbolic models according to the given training data. 
302
303        Parameters
304        ----------
305        X : array-like of shape (n_samples, n_features)
306            Training vector, where `n_samples` is the number of samples and
307            `n_features` is the number of features. Should be in the range [0, 1].
308
309        y : array-like of shape (n_samples,)
310            Target vector relative to X.
311
312        Returns
313        -------
314        self
315            Fitted estimator.
316        """
317
318        super().fit(X, y)
319        return self
320
321    def predict(self, X):
322        """
323        Predict class for X.
324
325        Parameters
326        ----------
327        X : array-like of shape (n_samples, n_features)
328            The input samples.
329
330        Returns
331        -------
332        y : ndarray of shape (n_samples,)
333            The predicted classes.
334        """
335        return super().predict(X)
336
337    def predict_proba(self, X):
338        """
339        Predict class probabilities for X.
340
341        Parameters
342        ----------
343        X : narray-like of shape (n_samples, n_features)
344
345        Returns
346        -------
347        T : ndarray of shape (n_samples, n_classes)
348            The class probabilities of the input samples. The order of the
349            classes corresponds to that in the attribute :term:`classes_`.
350        """
351        return super().predict_proba(X)

OVR multiclass symbolic classificator

Parameters
  • estimator (NonlinearLogisticRegressor): Instance of NonlinearLogisticRegressor class.
SymbolicClassifier(estimator=NonlinearLogisticRegressor())
296    def __init__(self, estimator=NonlinearLogisticRegressor()):
297        super().__init__(estimator=estimator)
def fit(self, X, y):
299    def fit(self, X, y):
300        """
301        Fit the symbolic models according to the given training data. 
302
303        Parameters
304        ----------
305        X : array-like of shape (n_samples, n_features)
306            Training vector, where `n_samples` is the number of samples and
307            `n_features` is the number of features. Should be in the range [0, 1].
308
309        y : array-like of shape (n_samples,)
310            Target vector relative to X.
311
312        Returns
313        -------
314        self
315            Fitted estimator.
316        """
317
318        super().fit(X, y)
319        return self

Fit the symbolic models according to the given training data.

Parameters
  • X (array-like of shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features. Should be in the range [0, 1].
  • y (array-like of shape (n_samples,)): Target vector relative to X.
Returns
  • self: Fitted estimator.
def predict(self, X):
321    def predict(self, X):
322        """
323        Predict class for X.
324
325        Parameters
326        ----------
327        X : array-like of shape (n_samples, n_features)
328            The input samples.
329
330        Returns
331        -------
332        y : ndarray of shape (n_samples,)
333            The predicted classes.
334        """
335        return super().predict(X)

Predict class for X.

Parameters
  • X (array-like of shape (n_samples, n_features)): The input samples.
Returns
  • y (ndarray of shape (n_samples,)): The predicted classes.
def predict_proba(self, X):
337    def predict_proba(self, X):
338        """
339        Predict class probabilities for X.
340
341        Parameters
342        ----------
343        X : narray-like of shape (n_samples, n_features)
344
345        Returns
346        -------
347        T : ndarray of shape (n_samples, n_classes)
348            The class probabilities of the input samples. The order of the
349            classes corresponds to that in the attribute :term:`classes_`.
350        """
351        return super().predict_proba(X)

Predict class probabilities for X.

Parameters
  • X (narray-like of shape (n_samples, n_features)):
Returns
  • T (ndarray of shape (n_samples, n_classes)): The class probabilities of the input samples. The order of the classes corresponds to that in the attribute :term:classes_.
def set_partial_fit_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_score_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
Inherited Members
sklearn.multiclass.OneVsRestClassifier
estimator
n_jobs
verbose
partial_fit
decision_function
multilabel_
n_classes_
get_metadata_routing
sklearn.base.ClassifierMixin
score
sklearn.base.BaseEstimator
get_params
set_params
class FuzzyRegressor(HROCH.hroch.SymbolicSolver, sklearn.base.ClassifierMixin):
 10class FuzzyRegressor(SymbolicSolver, ClassifierMixin):
 11    """
 12    Fuzzy Regressor
 13
 14    Parameters
 15    ----------
 16    num_threads : int, default=1
 17        Number of used threads.
 18
 19    time_limit : float, default=5.0
 20        Timeout in seconds. If is set to 0 there is no limit and the algorithm runs until iter_limit is met.
 21
 22    iter_limit : int, default=0
 23        Iterations limit. If is set to 0 there is no limit and the algorithm runs until time_limit is met.
 24
 25    precision : str, default='f32'
 26        'f64' or 'f32'. Internal floating number representation.
 27
 28    problem : str or dict, default='fuzzy'
 29        Predefined instructions sets 'fuzzy' or custom defines set of instructions with mutation probability.
 30        ```python
 31        problem={'f_and':10.0, 'f_or':10.0, 'f_xor':1.0, 'f_not':1.0, 'nop':1.0}
 32        ```
 33
 34        |**supported instructions**||
 35        |-|-|
 36        |**other**|nop|
 37        |**fuzzy**|f_and, f_or, f_xor, f_impl, f_not, f_nand, f_nor, f_nxor, f_nimpl|
 38
 39    feature_probs : array of shape (n_features,), default=None
 40        The probability that a mutation will select a feature.
 41
 42    random_state : int, default=0
 43        Random generator seed. If 0 then random generator will be initialized by system time.
 44
 45    verbose : int, default=0
 46        Controls the verbosity when fitting and predicting.
 47
 48    metric : str, default='LogLoss'
 49        Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'}
 50
 51    transformation : str, default=None
 52        Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'}
 53
 54    algo_settings : dict, default = None
 55        If not defined SymbolicSolver.ALGO_SETTINGS is used.
 56        ```python
 57        algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16}
 58        ```
 59        - 'neighbours_count' : (int) Number tested neighbours in each iteration
 60        - 'alpha' : (float) Score worsening limit for a iteration
 61        - 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1
 62        - 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating
 63        - 'sample_size : (int) Number of batches of sample used to calculate the score during training
 64
 65    code_settings : dict, default = None
 66        If not defined SymbolicSolver.CODE_SETTINGS is used.
 67        ```python
 68        code_settings = {'min_size': 32, 'max_size':32, 'const_size':8}
 69        ```
 70        - 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0.
 71        - 'min_size': (int) Minimum allowed equation size(as a linear program).
 72        - 'max_size' : (int) Maximum allowed equation size(as a linear program).
 73        
 74    population_settings : dict, default = None
 75        If not defined SymbolicSolver.POPULATION_SETTINGS is used.
 76        ```python
 77        population_settings = {'size': 64, 'tournament':4}
 78        ```
 79        - 'size' : (int) Number of individuals in the population.
 80        - 'tournament' : (int) Tournament selection.
 81
 82    init_const_settings : dict, default = None
 83        If not defined FuzzyRegressor.INIT_CONST_SETTINGS is used.
 84        ```python
 85        init_const_settings = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
 86        ```
 87        - 'const_min' : (float) Lower range for initializing constants.
 88        - 'const_max' : (float) Upper range for initializing constants.
 89        - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization.
 90        - 'predefined_const_set' : (array of floats) Predefined constants used during initialization.
 91
 92    const_settings : dict, default = None
 93        If not defined FuzzyRegressor.CONST_SETTINGS is used.
 94        ```python
 95        const_settings = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
 96        ```
 97        - 'const_min' : (float) Lower range for constants used in equations.
 98        - 'const_max' : (float) Upper range for constants used in equations.
 99        - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation).
100        - 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation).
101
102    target_clip : array, default = None
103        Array of two float values clip_min and clip_max.
104        If not defined SymbolicSolver.CLASSIFICATION_TARGET_CLIP is used.
105        ```python
106        target_clip=[3e-7, 1.0-3e-7]
107        ```
108    class_weight : dict or 'balanced', default=None
109        Weights associated with classes in the form ``{class_label: weight}``.
110        If not given, all classes are supposed to have weight one.
111
112        The "balanced" mode uses the values of y to automatically adjust
113        weights inversely proportional to class frequencies in the input data
114        as ``n_samples / (n_classes * np.bincount(y))``.
115
116        Note that these weights will be multiplied with sample_weight (passed
117        through the fit method) if sample_weight is specified.
118
119    cv_params : dict, default = None
120        If not defined SymbolicSolver.CLASSIFICATION_CV_PARAMS is used.
121        ```python
122        cv_params = {'n':0, 'cv_params':{}, 'select':'mean', 'opt_params':{'method': 'Nelder-Mead'}, 'opt_metric':make_scorer(log_loss, greater_is_better=False, needs_proba=True)}
123        ```
124        - 'n' : (int) Crossvalidate n top models
125        - 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method
126        - select : (str) Best model selection method choose from 'mean'or 'median'
127        - opt_params : (dict) Parameters passed to scipy.optimize.minimize method
128        - opt_metric : (make_scorer) Scoring method
129        
130    warm_start : bool, default=False
131        If True, then the solver will be reused for the next call of fit.
132    """
133    
134    INIT_CONST_SETTINGS = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
135    CONST_SETTINGS = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
136
137    def __init__(self,
138                 num_threads: int = 1,
139                 time_limit: float = 5.0,
140                 iter_limit: int = 0,
141                 precision: str = 'f32',
142                 problem = 'fuzzy',
143                 feature_probs = None,
144                 random_state: int = 0,
145                 verbose: int = 0,
146                 metric: str = 'LogLoss',
147                 transformation: str = None,
148                 algo_settings = None,
149                 code_settings = None,
150                 population_settings = None,
151                 init_const_settings = None,
152                 const_settings = None,
153                 target_clip = None,
154                 class_weight = None,
155                 cv_params = None,
156                 warm_start : bool = False
157                 ):
158        super(FuzzyRegressor, self).__init__(
159            num_threads=num_threads,
160            time_limit=time_limit,
161            iter_limit=iter_limit,
162            precision=precision,
163            problem=problem,
164            feature_probs=feature_probs,
165            random_state=random_state,
166            verbose=verbose,
167            metric=metric,
168            algo_settings=algo_settings,
169            transformation=transformation,
170            code_settings=code_settings,
171            population_settings=population_settings,
172            init_const_settings=init_const_settings,
173            const_settings=const_settings,
174            target_clip=target_clip,
175            class_weight=class_weight,
176            cv_params=cv_params,
177            warm_start=warm_start
178        )
179
180    def fit(self, X, y, sample_weight=None, check_input=True):
181        """
182        Fit the symbolic models according to the given training data. 
183
184        Parameters
185        ----------
186        X : array-like of shape (n_samples, n_features)
187            Training vector, where `n_samples` is the number of samples and
188            `n_features` is the number of features. Should be in the range [0, 1].
189
190        y : array-like of shape (n_samples,)
191            Target vector relative to X. Needs samples of 2 classes.
192
193        sample_weight : array-like of shape (n_samples,) default=None
194            Array of weights that are assigned to individual samples.
195            If not provided, then each sample is given unit weight.
196
197        check_input : bool, default=True
198            Allow to bypass several input checking.
199            Don't use this parameter unless you know what you're doing.
200
201        Returns
202        -------
203        self
204            Fitted estimator.
205        """
206        if check_input:
207            X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False)
208        check_classification_targets(y)
209        enc = LabelEncoder()
210        y_ind = enc.fit_transform(y)
211        self.classes_ = enc.classes_
212        self.n_classes_ = len(self.classes_)
213        if self.n_classes_ != 2:
214            raise ValueError(
215                "This solver needs samples of 2 classes"
216                " in the data, but the data contains"
217                " %r classes"
218                % self.n_classes_
219            )
220
221        self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y)
222
223        super(FuzzyRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=check_input)
224        return self
225
226    def predict(self, X, id=None, check_input=True, use_parsed_model=True):
227        """
228        Predict class for X.
229
230        Parameters
231        ----------
232        X : array-like of shape (n_samples, n_features)
233            The input samples.
234            
235        id : int
236            Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
237
238        check_input : bool, default=True
239            Allow to bypass several input checking.
240            Don't use this parameter unless you know what you're doing.
241
242        Returns
243        -------
244        y : ndarray of shape (n_samples,)
245            The predicted classes.
246        """
247        preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model)
248        return self.classes_[(preds > 0.5).astype(int)]
249
250    def predict_proba(self, X, id=None, check_input=True):
251        """
252        Predict class probabilities for X.
253
254        Parameters
255        ----------
256        X : array-like of shape (n_samples, n_features)
257
258        check_input : bool, default=True
259            Allow to bypass several input checking.
260            Don't use this parameter unless you know what you're doing.
261
262        Returns
263        -------
264        T : ndarray of shape (n_samples, n_classes)
265            The class probabilities of the input samples. The order of the
266            classes corresponds to that in the attribute :term:`classes_`.
267        """
268        preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input)
269        proba = numpy.vstack([1 - preds, preds]).T
270        return proba
271    
272    def _more_tags(self):
273        return {
274            'binary_only': True,
275            'poor_score':True, # tests from check_estimator dont have fuzzy number type
276            }

Fuzzy Regressor

Parameters
  • num_threads (int, default=1): Number of used threads.
  • time_limit (float, default=5.0): Timeout in seconds. If is set to 0 there is no limit and the algorithm runs until iter_limit is met.
  • iter_limit (int, default=0): Iterations limit. If is set to 0 there is no limit and the algorithm runs until time_limit is met.
  • precision (str, default='f32'): 'f64' or 'f32'. Internal floating number representation.
  • problem (str or dict, default='fuzzy'): Predefined instructions sets 'fuzzy' or custom defines set of instructions with mutation probability.

    problem={'f_and':10.0, 'f_or':10.0, 'f_xor':1.0, 'f_not':1.0, 'nop':1.0}
    
    supported instructions
    other nop
    fuzzy f_and, f_or, f_xor, f_impl, f_not, f_nand, f_nor, f_nxor, f_nimpl
  • feature_probs (array of shape (n_features,), default=None): The probability that a mutation will select a feature.
  • random_state (int, default=0): Random generator seed. If 0 then random generator will be initialized by system time.
  • verbose (int, default=0): Controls the verbosity when fitting and predicting.
  • metric (str, default='LogLoss'): Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'}
  • transformation (str, default=None): Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'}
  • algo_settings (dict, default = None): If not defined SymbolicSolver.ALGO_SETTINGS is used.

    algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16}
    
    • 'neighbours_count' : (int) Number tested neighbours in each iteration
    • 'alpha' : (float) Score worsening limit for a iteration
    • 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1
    • 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating
    • 'sample_size : (int) Number of batches of sample used to calculate the score during training
  • code_settings (dict, default = None): If not defined SymbolicSolver.CODE_SETTINGS is used.

    code_settings = {'min_size': 32, 'max_size':32, 'const_size':8}
    
    • 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0.
    • 'min_size': (int) Minimum allowed equation size(as a linear program).
    • 'max_size' : (int) Maximum allowed equation size(as a linear program).
  • population_settings (dict, default = None): If not defined SymbolicSolver.POPULATION_SETTINGS is used.

    population_settings = {'size': 64, 'tournament':4}
    
    • 'size' : (int) Number of individuals in the population.
    • 'tournament' : (int) Tournament selection.
  • init_const_settings (dict, default = None): If not defined FuzzyRegressor.INIT_CONST_SETTINGS is used.

    init_const_settings = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
    
    • 'const_min' : (float) Lower range for initializing constants.
    • 'const_max' : (float) Upper range for initializing constants.
    • 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization.
    • 'predefined_const_set' : (array of floats) Predefined constants used during initialization.
  • const_settings (dict, default = None): If not defined FuzzyRegressor.CONST_SETTINGS is used.

    const_settings = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []}
    
    • 'const_min' : (float) Lower range for constants used in equations.
    • 'const_max' : (float) Upper range for constants used in equations.
    • 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation).
    • 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation).
  • target_clip (array, default = None): Array of two float values clip_min and clip_max. If not defined SymbolicSolver.CLASSIFICATION_TARGET_CLIP is used.

    target_clip=[3e-7, 1.0-3e-7]
    
  • class_weight (dict or 'balanced', default=None): Weights associated with classes in the form {class_label: weight}. If not given, all classes are supposed to have weight one.

    The "balanced" mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y)).

    Note that these weights will be multiplied with sample_weight (passed through the fit method) if sample_weight is specified.

  • cv_params (dict, default = None): If not defined SymbolicSolver.CLASSIFICATION_CV_PARAMS is used.

    cv_params = {'n':0, 'cv_params':{}, 'select':'mean', 'opt_params':{'method': 'Nelder-Mead'}, 'opt_metric':make_scorer(log_loss, greater_is_better=False, needs_proba=True)}
    
    • 'n' : (int) Crossvalidate n top models
    • 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method
    • select : (str) Best model selection method choose from 'mean'or 'median'
    • opt_params : (dict) Parameters passed to scipy.optimize.minimize method
    • opt_metric : (make_scorer) Scoring method
  • warm_start (bool, default=False): If True, then the solver will be reused for the next call of fit.
FuzzyRegressor( num_threads: int = 1, time_limit: float = 5.0, iter_limit: int = 0, precision: str = 'f32', problem='fuzzy', feature_probs=None, random_state: int = 0, verbose: int = 0, metric: str = 'LogLoss', transformation: str = None, algo_settings=None, code_settings=None, population_settings=None, init_const_settings=None, const_settings=None, target_clip=None, class_weight=None, cv_params=None, warm_start: bool = False)
137    def __init__(self,
138                 num_threads: int = 1,
139                 time_limit: float = 5.0,
140                 iter_limit: int = 0,
141                 precision: str = 'f32',
142                 problem = 'fuzzy',
143                 feature_probs = None,
144                 random_state: int = 0,
145                 verbose: int = 0,
146                 metric: str = 'LogLoss',
147                 transformation: str = None,
148                 algo_settings = None,
149                 code_settings = None,
150                 population_settings = None,
151                 init_const_settings = None,
152                 const_settings = None,
153                 target_clip = None,
154                 class_weight = None,
155                 cv_params = None,
156                 warm_start : bool = False
157                 ):
158        super(FuzzyRegressor, self).__init__(
159            num_threads=num_threads,
160            time_limit=time_limit,
161            iter_limit=iter_limit,
162            precision=precision,
163            problem=problem,
164            feature_probs=feature_probs,
165            random_state=random_state,
166            verbose=verbose,
167            metric=metric,
168            algo_settings=algo_settings,
169            transformation=transformation,
170            code_settings=code_settings,
171            population_settings=population_settings,
172            init_const_settings=init_const_settings,
173            const_settings=const_settings,
174            target_clip=target_clip,
175            class_weight=class_weight,
176            cv_params=cv_params,
177            warm_start=warm_start
178        )
INIT_CONST_SETTINGS = {'const_min': 0.0, 'const_max': 1.0, 'predefined_const_prob': 0.0, 'predefined_const_set': []}
CONST_SETTINGS = {'const_min': 0.0, 'const_max': 1.0, 'predefined_const_prob': 0.0, 'predefined_const_set': []}
def fit(self, X, y, sample_weight=None, check_input=True):
180    def fit(self, X, y, sample_weight=None, check_input=True):
181        """
182        Fit the symbolic models according to the given training data. 
183
184        Parameters
185        ----------
186        X : array-like of shape (n_samples, n_features)
187            Training vector, where `n_samples` is the number of samples and
188            `n_features` is the number of features. Should be in the range [0, 1].
189
190        y : array-like of shape (n_samples,)
191            Target vector relative to X. Needs samples of 2 classes.
192
193        sample_weight : array-like of shape (n_samples,) default=None
194            Array of weights that are assigned to individual samples.
195            If not provided, then each sample is given unit weight.
196
197        check_input : bool, default=True
198            Allow to bypass several input checking.
199            Don't use this parameter unless you know what you're doing.
200
201        Returns
202        -------
203        self
204            Fitted estimator.
205        """
206        if check_input:
207            X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False)
208        check_classification_targets(y)
209        enc = LabelEncoder()
210        y_ind = enc.fit_transform(y)
211        self.classes_ = enc.classes_
212        self.n_classes_ = len(self.classes_)
213        if self.n_classes_ != 2:
214            raise ValueError(
215                "This solver needs samples of 2 classes"
216                " in the data, but the data contains"
217                " %r classes"
218                % self.n_classes_
219            )
220
221        self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y)
222
223        super(FuzzyRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=check_input)
224        return self

Fit the symbolic models according to the given training data.

Parameters
  • X (array-like of shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features. Should be in the range [0, 1].
  • y (array-like of shape (n_samples,)): Target vector relative to X. Needs samples of 2 classes.
  • sample_weight (array-like of shape (n_samples,) default=None): Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • self: Fitted estimator.
def predict(self, X, id=None, check_input=True, use_parsed_model=True):
226    def predict(self, X, id=None, check_input=True, use_parsed_model=True):
227        """
228        Predict class for X.
229
230        Parameters
231        ----------
232        X : array-like of shape (n_samples, n_features)
233            The input samples.
234            
235        id : int
236            Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
237
238        check_input : bool, default=True
239            Allow to bypass several input checking.
240            Don't use this parameter unless you know what you're doing.
241
242        Returns
243        -------
244        y : ndarray of shape (n_samples,)
245            The predicted classes.
246        """
247        preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model)
248        return self.classes_[(preds > 0.5).astype(int)]

Predict class for X.

Parameters
  • X (array-like of shape (n_samples, n_features)): The input samples.
  • id (int): Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • y (ndarray of shape (n_samples,)): The predicted classes.
def predict_proba(self, X, id=None, check_input=True):
250    def predict_proba(self, X, id=None, check_input=True):
251        """
252        Predict class probabilities for X.
253
254        Parameters
255        ----------
256        X : array-like of shape (n_samples, n_features)
257
258        check_input : bool, default=True
259            Allow to bypass several input checking.
260            Don't use this parameter unless you know what you're doing.
261
262        Returns
263        -------
264        T : ndarray of shape (n_samples, n_classes)
265            The class probabilities of the input samples. The order of the
266            classes corresponds to that in the attribute :term:`classes_`.
267        """
268        preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input)
269        proba = numpy.vstack([1 - preds, preds]).T
270        return proba

Predict class probabilities for X.

Parameters
  • X (array-like of shape (n_samples, n_features)):

  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.

Returns
  • T (ndarray of shape (n_samples, n_classes)): The class probabilities of the input samples. The order of the classes corresponds to that in the attribute :term:classes_.
def set_fit_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_proba_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_score_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
Inherited Members
HROCH.hroch.SymbolicSolver
LARGE_FLOAT
SIMPLE
MATH
FUZZY
ALGO_SETTINGS
CODE_SETTINGS
POPULATION_SETTINGS
REGRESSION_CV_PARAMS
CLASSIFICATION_CV_PARAMS
REGRESSION_TARGET_CLIP
CLASSIFICATION_TARGET_CLIP
num_threads
time_limit
iter_limit
verbose
precision
problem
feature_probs
random_state
code_settings
population_settings
metric
transformation
algo_settings
init_const_settings
const_settings
target_clip
class_weight
cv_params
warm_start
equation
get_models
sklearn.base.BaseEstimator
get_params
set_params
sklearn.utils._metadata_requests._MetadataRequester
get_metadata_routing
sklearn.base.ClassifierMixin
score
class FuzzyClassifier(sklearn.multiclass.OneVsRestClassifier):
279class FuzzyClassifier(OneVsRestClassifier):
280    """
281    Fuzzy multiclass symbolic classificator
282    
283    Parameters
284    ----------
285    estimator : FuzzyRegressor
286        Instance of FuzzyRegressor class.
287    """
288    def __init__(self, estimator=FuzzyRegressor()):
289        super().__init__(estimator=estimator)
290    
291    def fit(self, X, y):
292        """
293        Fit the symbolic models according to the given training data. 
294
295        Parameters
296        ----------
297        X : array-like of shape (n_samples, n_features)
298            Training vector, where `n_samples` is the number of samples and
299            `n_features` is the number of features. Should be in the range [0, 1].
300
301        y : array-like of shape (n_samples,)
302            Target vector relative to X.
303
304        Returns
305        -------
306        self
307            Fitted estimator.
308        """
309
310        super().fit(X, y)
311        return self
312
313    def predict(self, X):
314        """
315        Predict class for X.
316
317        Parameters
318        ----------
319        X : array-like of shape (n_samples, n_features)
320            The input samples.
321
322        Returns
323        -------
324        y : ndarray of shape (n_samples,)
325            The predicted classes.
326        """
327        return super().predict(X)
328
329    def predict_proba(self, X):
330        """
331        Predict class probabilities for X.
332
333        Parameters
334        ----------
335        X : array-like of shape (n_samples, n_features)
336
337        Returns
338        -------
339        T : ndarray of shape (n_samples, n_classes)
340            The class probabilities of the input samples. The order of the
341            classes corresponds to that in the attribute :term:`classes_`.
342        """
343        return super().predict_proba(X)
344    
345    def _more_tags(self):
346        return {
347            'poor_score':True, # tests from check_estimator dont have fuzzy number type
348            }

Fuzzy multiclass symbolic classificator

Parameters
  • estimator (FuzzyRegressor): Instance of FuzzyRegressor class.
FuzzyClassifier(estimator=FuzzyRegressor())
288    def __init__(self, estimator=FuzzyRegressor()):
289        super().__init__(estimator=estimator)
def fit(self, X, y):
291    def fit(self, X, y):
292        """
293        Fit the symbolic models according to the given training data. 
294
295        Parameters
296        ----------
297        X : array-like of shape (n_samples, n_features)
298            Training vector, where `n_samples` is the number of samples and
299            `n_features` is the number of features. Should be in the range [0, 1].
300
301        y : array-like of shape (n_samples,)
302            Target vector relative to X.
303
304        Returns
305        -------
306        self
307            Fitted estimator.
308        """
309
310        super().fit(X, y)
311        return self

Fit the symbolic models according to the given training data.

Parameters
  • X (array-like of shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features. Should be in the range [0, 1].
  • y (array-like of shape (n_samples,)): Target vector relative to X.
Returns
  • self: Fitted estimator.
def predict(self, X):
313    def predict(self, X):
314        """
315        Predict class for X.
316
317        Parameters
318        ----------
319        X : array-like of shape (n_samples, n_features)
320            The input samples.
321
322        Returns
323        -------
324        y : ndarray of shape (n_samples,)
325            The predicted classes.
326        """
327        return super().predict(X)

Predict class for X.

Parameters
  • X (array-like of shape (n_samples, n_features)): The input samples.
Returns
  • y (ndarray of shape (n_samples,)): The predicted classes.
def predict_proba(self, X):
329    def predict_proba(self, X):
330        """
331        Predict class probabilities for X.
332
333        Parameters
334        ----------
335        X : array-like of shape (n_samples, n_features)
336
337        Returns
338        -------
339        T : ndarray of shape (n_samples, n_classes)
340            The class probabilities of the input samples. The order of the
341            classes corresponds to that in the attribute :term:`classes_`.
342        """
343        return super().predict_proba(X)

Predict class probabilities for X.

Parameters
  • X (array-like of shape (n_samples, n_features)):
Returns
  • T (ndarray of shape (n_samples, n_classes)): The class probabilities of the input samples. The order of the classes corresponds to that in the attribute :term:classes_.
def set_partial_fit_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_score_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
Inherited Members
sklearn.multiclass.OneVsRestClassifier
estimator
n_jobs
verbose
partial_fit
decision_function
multilabel_
n_classes_
get_metadata_routing
sklearn.base.ClassifierMixin
score
sklearn.base.BaseEstimator
get_params
set_params
class RegressorMathModel(HROCH.hroch.MathModelBase, sklearn.base.RegressorMixin):
178class RegressorMathModel(MathModelBase, RegressorMixin):
179    """
180    A regressor class for the symbolic model.
181    """
182    def __init__(self, m: ParsedMathModel, opt_metric, opt_params, transformation, target_clip) -> None:
183        super().__init__(m, opt_metric, opt_params, transformation, target_clip, None, None)
184
185    def fit(self, X, y, sample_weight=None, check_input=True):
186        """
187        Fit the model according to the given training data. 
188        
189        That means find a optimal values for constants in a symbolic equation.
190
191        Parameters
192        ----------
193        X : array-like of shape (n_samples, n_features)
194            Training vector, where `n_samples` is the number of samples and
195            `n_features` is the number of features.
196
197        y : array-like of shape (n_samples,)
198            Target vector relative to X.
199
200        sample_weight : array-like of shape (n_samples,) default=None
201            Array of weights that are assigned to individual samples.
202            If not provided, then each sample is given unit weight.
203
204        check_input : bool, default=True
205            Allow to bypass several input checking.
206            Don't use this parameter unless you know what you're doing.
207
208        Returns
209        -------
210        self
211            Fitted estimator.
212        """
213
214        def objective(c):
215            return self.__eval(X, y, metric=self.opt_metric, c=c, sample_weight=sample_weight)
216
217        if len(self.m.coeffs) > 0:
218            result = opt.minimize(objective, self.m.coeffs, **self.opt_params)
219
220            for i in range(len(self.m.coeffs)):
221                self.m.coeffs[i] = result.x[i]
222
223        self.is_fitted_ = True
224        return self
225
226    def predict(self, X, check_input=True):
227        """
228        Predict regression target for X.
229
230        Parameters
231        ----------
232        X : array-like of shape (n_samples, n_features)
233            The input samples.
234
235        check_input : bool, default=True
236            Allow to bypass several input checking.
237            Don't use this parameter unless you know what you're doing.
238
239        Returns
240        -------
241        y : ndarray of shape (n_samples,) or (n_samples, n_outputs)
242            The predicted values.
243        """
244        return self._predict(X)
245    
246    def __eval(self, X, y, metric, c=None, sample_weight=None):
247        if c is not None:
248            self.m.coeffs = c
249        try:
250            return -metric(self, X, y, sample_weight=sample_weight)
251        except:
252            return SymbolicSolver.LARGE_FLOAT
253    
254    def __str__(self):
255        return f"RegressorMathModel({self.m.str_representation})"
256    
257    def __repr__(self):
258        return f"RegressorMathModel({self.m.str_representation})"

A regressor class for the symbolic model.

RegressorMathModel( m: HROCH.hroch.ParsedMathModel, opt_metric, opt_params, transformation, target_clip)
182    def __init__(self, m: ParsedMathModel, opt_metric, opt_params, transformation, target_clip) -> None:
183        super().__init__(m, opt_metric, opt_params, transformation, target_clip, None, None)
def fit(self, X, y, sample_weight=None, check_input=True):
185    def fit(self, X, y, sample_weight=None, check_input=True):
186        """
187        Fit the model according to the given training data. 
188        
189        That means find a optimal values for constants in a symbolic equation.
190
191        Parameters
192        ----------
193        X : array-like of shape (n_samples, n_features)
194            Training vector, where `n_samples` is the number of samples and
195            `n_features` is the number of features.
196
197        y : array-like of shape (n_samples,)
198            Target vector relative to X.
199
200        sample_weight : array-like of shape (n_samples,) default=None
201            Array of weights that are assigned to individual samples.
202            If not provided, then each sample is given unit weight.
203
204        check_input : bool, default=True
205            Allow to bypass several input checking.
206            Don't use this parameter unless you know what you're doing.
207
208        Returns
209        -------
210        self
211            Fitted estimator.
212        """
213
214        def objective(c):
215            return self.__eval(X, y, metric=self.opt_metric, c=c, sample_weight=sample_weight)
216
217        if len(self.m.coeffs) > 0:
218            result = opt.minimize(objective, self.m.coeffs, **self.opt_params)
219
220            for i in range(len(self.m.coeffs)):
221                self.m.coeffs[i] = result.x[i]
222
223        self.is_fitted_ = True
224        return self

Fit the model according to the given training data.

That means find a optimal values for constants in a symbolic equation.

Parameters
  • X (array-like of shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features.
  • y (array-like of shape (n_samples,)): Target vector relative to X.
  • sample_weight (array-like of shape (n_samples,) default=None): Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • self: Fitted estimator.
def predict(self, X, check_input=True):
226    def predict(self, X, check_input=True):
227        """
228        Predict regression target for X.
229
230        Parameters
231        ----------
232        X : array-like of shape (n_samples, n_features)
233            The input samples.
234
235        check_input : bool, default=True
236            Allow to bypass several input checking.
237            Don't use this parameter unless you know what you're doing.
238
239        Returns
240        -------
241        y : ndarray of shape (n_samples,) or (n_samples, n_outputs)
242            The predicted values.
243        """
244        return self._predict(X)

Predict regression target for X.

Parameters
  • X (array-like of shape (n_samples, n_features)): The input samples.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • y (ndarray of shape (n_samples,) or (n_samples, n_outputs)): The predicted values.
def set_fit_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_score_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
Inherited Members
HROCH.hroch.MathModelBase
m
opt_metric
opt_params
transformation
target_clip
class_weight_
classes_
is_fitted_
equation
sklearn.base.BaseEstimator
get_params
set_params
sklearn.utils._metadata_requests._MetadataRequester
get_metadata_routing
sklearn.base.RegressorMixin
score
class ClassifierMathModel(HROCH.hroch.MathModelBase, sklearn.base.ClassifierMixin):
261class ClassifierMathModel(MathModelBase, ClassifierMixin):
262    """
263    A classifier class for the symbolic model.
264    """
265    def __init__(self, m: ParsedMathModel, opt_metric, opt_params, transformation, target_clip, class_weight_, classes_) -> None:
266        super().__init__(m, opt_metric, opt_params, transformation, target_clip, class_weight_, classes_)
267
268    def fit(self, X, y, sample_weight=None, check_input=True):
269        """
270        Fit the model according to the given training data. 
271        
272        That means find a optimal values for constants in a symbolic equation.
273
274        Parameters
275        ----------
276        X : array-like of shape (n_samples, n_features)
277            Training vector, where `n_samples` is the number of samples and
278            `n_features` is the number of features.
279
280        y : array-like of shape (n_samples,)
281            Target vector relative to X. Needs samples of 2 classes.
282
283        sample_weight : array-like of shape (n_samples,) default=None
284            Array of weights that are assigned to individual samples.
285            If not provided, then each sample is given unit weight.
286
287        check_input : bool, default=True
288            Allow to bypass several input checking.
289            Don't use this parameter unless you know what you're doing.
290
291        Returns
292        -------
293        self
294            Fitted estimator.
295        """
296
297        check_classification_targets(y)
298        enc = LabelEncoder()
299        y_ind = enc.fit_transform(y)
300        self.classes_ = enc.classes_
301        self.n_classes_ = len(self.classes_)
302        if self.n_classes_ != 2:
303            raise ValueError(
304                "This solver needs samples of 2 classes"
305                " in the data, but the data contains"
306                " %r classes"
307                % self.n_classes_
308            )
309        
310        cw = self.class_weight_
311        cw_sample_weight = numpy.array(cw)[y_ind] if len(cw) == 2 and cw[0] != cw[1] else None
312        if sample_weight is None:
313            sample_weight = cw_sample_weight
314        elif cw_sample_weight is not None:
315            sample_weight = sample_weight*cw_sample_weight
316
317        def objective(c):
318            return self.__eval(X, y, metric=self.opt_metric, c=c, sample_weight=sample_weight)
319
320        if len(self.m.coeffs) > 0:
321            result = opt.minimize(objective, self.m.coeffs,
322                                  **self.opt_params)
323
324            for i in range(len(self.m.coeffs)):
325                self.m.coeffs[i] = result.x[i]
326
327        self.is_fitted_ = True
328        return self
329
330    def predict(self, X, check_input=True):
331        """
332        Predict class for X.
333
334        Parameters
335        ----------
336        X : array-like of shape (n_samples, n_features)
337            The input samples.
338
339        check_input : bool, default=True
340            Allow to bypass several input checking.
341            Don't use this parameter unless you know what you're doing.
342
343        Returns
344        -------
345        y : ndarray of shape (n_samples,)
346            The predicted classes.
347        """
348        preds = self._predict(X, check_input=check_input)
349        return self.classes_[(preds > 0.5).astype(int)]
350
351    def predict_proba(self, X, check_input=True):
352        """
353        Predict class probabilities for X.
354
355        Parameters
356        ----------
357        X : array-like of shape (n_samples, n_features)
358
359        check_input : bool, default=True
360            Allow to bypass several input checking.
361            Don't use this parameter unless you know what you're doing.
362
363        Returns
364        -------
365        T : ndarray of shape (n_samples, n_classes)
366            The class probabilities of the input samples. The order of the
367            classes corresponds to that in the attribute :term:`classes_`.
368        """
369        preds = self._predict(X, check_input=check_input)
370        proba = numpy.vstack([1 - preds, preds]).T
371        return proba
372    
373    def __eval(self, X, y, metric, c=None, sample_weight=None):
374        if c is not None:
375            self.m.coeffs = c
376        try:
377            return -metric(self, X, y, sample_weight=sample_weight)
378        except:
379            return SymbolicSolver.LARGE_FLOAT
380    
381    def __str__(self):
382        return f"ClassifierMathModel({self.m.str_representation})"
383    
384    def __repr__(self):
385        return f"ClassifierMathModel({self.m.str_representation})"

A classifier class for the symbolic model.

ClassifierMathModel( m: HROCH.hroch.ParsedMathModel, opt_metric, opt_params, transformation, target_clip, class_weight_, classes_)
265    def __init__(self, m: ParsedMathModel, opt_metric, opt_params, transformation, target_clip, class_weight_, classes_) -> None:
266        super().__init__(m, opt_metric, opt_params, transformation, target_clip, class_weight_, classes_)
def fit(self, X, y, sample_weight=None, check_input=True):
268    def fit(self, X, y, sample_weight=None, check_input=True):
269        """
270        Fit the model according to the given training data. 
271        
272        That means find a optimal values for constants in a symbolic equation.
273
274        Parameters
275        ----------
276        X : array-like of shape (n_samples, n_features)
277            Training vector, where `n_samples` is the number of samples and
278            `n_features` is the number of features.
279
280        y : array-like of shape (n_samples,)
281            Target vector relative to X. Needs samples of 2 classes.
282
283        sample_weight : array-like of shape (n_samples,) default=None
284            Array of weights that are assigned to individual samples.
285            If not provided, then each sample is given unit weight.
286
287        check_input : bool, default=True
288            Allow to bypass several input checking.
289            Don't use this parameter unless you know what you're doing.
290
291        Returns
292        -------
293        self
294            Fitted estimator.
295        """
296
297        check_classification_targets(y)
298        enc = LabelEncoder()
299        y_ind = enc.fit_transform(y)
300        self.classes_ = enc.classes_
301        self.n_classes_ = len(self.classes_)
302        if self.n_classes_ != 2:
303            raise ValueError(
304                "This solver needs samples of 2 classes"
305                " in the data, but the data contains"
306                " %r classes"
307                % self.n_classes_
308            )
309        
310        cw = self.class_weight_
311        cw_sample_weight = numpy.array(cw)[y_ind] if len(cw) == 2 and cw[0] != cw[1] else None
312        if sample_weight is None:
313            sample_weight = cw_sample_weight
314        elif cw_sample_weight is not None:
315            sample_weight = sample_weight*cw_sample_weight
316
317        def objective(c):
318            return self.__eval(X, y, metric=self.opt_metric, c=c, sample_weight=sample_weight)
319
320        if len(self.m.coeffs) > 0:
321            result = opt.minimize(objective, self.m.coeffs,
322                                  **self.opt_params)
323
324            for i in range(len(self.m.coeffs)):
325                self.m.coeffs[i] = result.x[i]
326
327        self.is_fitted_ = True
328        return self

Fit the model according to the given training data.

That means find a optimal values for constants in a symbolic equation.

Parameters
  • X (array-like of shape (n_samples, n_features)): Training vector, where n_samples is the number of samples and n_features is the number of features.
  • y (array-like of shape (n_samples,)): Target vector relative to X. Needs samples of 2 classes.
  • sample_weight (array-like of shape (n_samples,) default=None): Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • self: Fitted estimator.
def predict(self, X, check_input=True):
330    def predict(self, X, check_input=True):
331        """
332        Predict class for X.
333
334        Parameters
335        ----------
336        X : array-like of shape (n_samples, n_features)
337            The input samples.
338
339        check_input : bool, default=True
340            Allow to bypass several input checking.
341            Don't use this parameter unless you know what you're doing.
342
343        Returns
344        -------
345        y : ndarray of shape (n_samples,)
346            The predicted classes.
347        """
348        preds = self._predict(X, check_input=check_input)
349        return self.classes_[(preds > 0.5).astype(int)]

Predict class for X.

Parameters
  • X (array-like of shape (n_samples, n_features)): The input samples.
  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.
Returns
  • y (ndarray of shape (n_samples,)): The predicted classes.
def predict_proba(self, X, check_input=True):
351    def predict_proba(self, X, check_input=True):
352        """
353        Predict class probabilities for X.
354
355        Parameters
356        ----------
357        X : array-like of shape (n_samples, n_features)
358
359        check_input : bool, default=True
360            Allow to bypass several input checking.
361            Don't use this parameter unless you know what you're doing.
362
363        Returns
364        -------
365        T : ndarray of shape (n_samples, n_classes)
366            The class probabilities of the input samples. The order of the
367            classes corresponds to that in the attribute :term:`classes_`.
368        """
369        preds = self._predict(X, check_input=check_input)
370        proba = numpy.vstack([1 - preds, preds]).T
371        return proba

Predict class probabilities for X.

Parameters
  • X (array-like of shape (n_samples, n_features)):

  • check_input (bool, default=True): Allow to bypass several input checking. Don't use this parameter unless you know what you're doing.

Returns
  • T (ndarray of shape (n_samples, n_classes)): The class probabilities of the input samples. The order of the classes corresponds to that in the attribute :term:classes_.
def set_fit_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_predict_proba_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
def set_score_request(unknown):

A descriptor for request methods.

New in version 1.3.

Parameters
  • name (str): The name of the method for which the request function should be created, e.g. "fit" would create a set_fit_request function.
  • keys (list of str): A list of strings which are accepted parameters by the created function, e.g. ["sample_weight"] if the corresponding method accepts it as a metadata.
  • validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes

This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.

References
Inherited Members
HROCH.hroch.MathModelBase
m
opt_metric
opt_params
transformation
target_clip
class_weight_
classes_
is_fitted_
equation
sklearn.base.BaseEstimator
get_params
set_params
sklearn.utils._metadata_requests._MetadataRequester
get_metadata_routing
sklearn.base.ClassifierMixin
score
__version__ = '1.4.11'