HROCH
Symbolic regression and classification library
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
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
- Xi corelation used for filter unrelated features
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
1""" 2.. include:: ../README.md 3""" 4from .hroch import RegressorMathModel, ClassifierMathModel, Xicor 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', 'Xicor', '__version__']
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 : str or array of shape (n_features,), default='xicor' 50 The probability that a mutation will select a feature. 51 If None then the features are selected with equal probability. 52 If 'xicor' then the probabilities are deriveded from xicor corelation coefficient https://doi.org/10.1080/01621459.2020.1758115 53 54 random_state : int, default=0 55 Random generator seed. If 0 then random generator will be initialized by system time. 56 57 verbose : int, default=0 58 Controls the verbosity when fitting and predicting. 59 60 metric : str, default='MSE' 61 Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'} 62 63 transformation : str, default=None 64 Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'} 65 66 algo_settings : dict, default = None 67 If not defined SymbolicSolver.ALGO_SETTINGS is used. 68 ```python 69 algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16} 70 ``` 71 - 'neighbours_count' : (int) Number tested neighbours in each iteration 72 - 'alpha' : (float) Score worsening limit for a iteration 73 - 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1 74 - 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating 75 - 'sample_size : (int) Number of batches of sample used to calculate the score during training 76 77 code_settings : dict, default = None 78 If not defined SymbolicSolver.CODE_SETTINGS is used. 79 ```python 80 code_settings = {'min_size': 32, 'max_size':32, 'const_size':8} 81 ``` 82 - 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0. 83 - 'min_size': (int) Minimum allowed equation size(as a linear program). 84 - 'max_size' : (int) Maximum allowed equation size(as a linear program). 85 86 population_settings : dict, default = None 87 If not defined SymbolicSolver.POPULATION_SETTINGS is used. 88 ```python 89 population_settings = {'size': 64, 'tournament':4} 90 ``` 91 - 'size' : (int) Number of individuals in the population. 92 - 'tournament' : (int) Tournament selection. 93 94 init_const_settings : dict, default = None 95 If not defined SymbolicSolver.INIT_CONST_SETTINGS is used. 96 ```python 97 init_const_settings = {'const_min':-1.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []} 98 ``` 99 - 'const_min' : (float) Lower range for initializing constants. 100 - 'const_max' : (float) Upper range for initializing constants. 101 - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization. 102 - 'predefined_const_set' : (array of floats) Predefined constants used during initialization. 103 104 const_settings : dict, default = None 105 If not defined SymbolicSolver.CONST_SETTINGS is used. 106 ```python 107 const_settings = {'const_min':-LARGE_FLOAT, 'const_max':LARGE_FLOAT, 'predefined_const_prob':0.0, 'predefined_const_set': []} 108 ``` 109 - 'const_min' : (float) Lower range for constants used in equations. 110 - 'const_max' : (float) Upper range for constants used in equations. 111 - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation). 112 - 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation). 113 114 target_clip : array of two float values clip_min and clip_max, default None 115 ```python 116 target_clip=[-1, 1] 117 ``` 118 119 cv_params : dict, default = None 120 If not defined SymbolicSolver.REGRESSION_CV_PARAMS is used 121 ```python 122 cv_params = {'n':0, 'cv_params':{}, 'select':'mean', 'opt_params':{'method': 'Nelder-Mead'}, 'opt_metric':make_scorer(mean_squared_error, greater_is_better=False)} 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 def __init__(self, 135 num_threads: int = 1, 136 time_limit: float = 5.0, 137 iter_limit: int = 0, 138 precision: str = 'f32', 139 problem = 'math', 140 feature_probs = 'xicor', 141 random_state: int = 0, 142 verbose: int = 0, 143 metric: str = 'MSE', 144 transformation: str = None, 145 algo_settings = None, 146 code_settings = None, 147 population_settings = None, 148 init_const_settings = None, 149 const_settings = None, 150 target_clip: Iterable = None, 151 cv_params = None, 152 warm_start : bool = False 153 ): 154 super(SymbolicRegressor, self).__init__( 155 num_threads=num_threads, 156 time_limit=time_limit, 157 iter_limit=iter_limit, 158 precision=precision, 159 problem=problem, 160 feature_probs=feature_probs, 161 random_state=random_state, 162 verbose=verbose, 163 metric=metric, 164 transformation=transformation, 165 algo_settings=algo_settings, 166 code_settings=code_settings, 167 population_settings=population_settings, 168 init_const_settings=init_const_settings, 169 const_settings=const_settings, 170 target_clip=target_clip, 171 class_weight=None, 172 cv_params=cv_params, 173 warm_start=warm_start 174 ) 175 176 def fit(self, X, y, sample_weight=None, check_input=True): 177 """ 178 Fit the symbolic models according to the given training data. 179 180 Parameters 181 ---------- 182 X : array-like of shape (n_samples, n_features) 183 Training vector, where `n_samples` is the number of samples and 184 `n_features` is the number of features. 185 186 y : array-like of shape (n_samples,) 187 Target vector relative to X. 188 189 sample_weight : array-like of shape (n_samples,) default=None 190 Array of weights that are assigned to individual samples. 191 If not provided, then each sample is given unit weight. 192 193 check_input : bool, default=True 194 Allow to bypass several input checking. 195 Don't use this parameter unless you know what you're doing. 196 197 Returns 198 ------- 199 self 200 Fitted estimator. 201 """ 202 203 super(SymbolicRegressor, self).fit(X, y, sample_weight=sample_weight, check_input=check_input) 204 return self 205 206 def predict(self, X, id=None, check_input=True, use_parsed_model=True): 207 """ 208 Predict regression target for X. 209 210 Parameters 211 ---------- 212 X : array-like of shape (n_samples, n_features) 213 The input samples. 214 215 id : int 216 Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model. 217 218 check_input : bool, default=True 219 Allow to bypass several input checking. 220 Don't use this parameter unless you know what you're doing. 221 222 Returns 223 ------- 224 y : ndarray of shape (n_samples,) or (n_samples, n_outputs) 225 The predicted values. 226 """ 227 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 (str or array of shape (n_features,), default='xicor'): The probability that a mutation will select a feature. If None then the features are selected with equal probability. If 'xicor' then the probabilities are deriveded from xicor corelation coefficient https://doi.org/10.1080/01621459.2020.1758115
- 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.
134 def __init__(self, 135 num_threads: int = 1, 136 time_limit: float = 5.0, 137 iter_limit: int = 0, 138 precision: str = 'f32', 139 problem = 'math', 140 feature_probs = 'xicor', 141 random_state: int = 0, 142 verbose: int = 0, 143 metric: str = 'MSE', 144 transformation: str = None, 145 algo_settings = None, 146 code_settings = None, 147 population_settings = None, 148 init_const_settings = None, 149 const_settings = None, 150 target_clip: Iterable = None, 151 cv_params = None, 152 warm_start : bool = False 153 ): 154 super(SymbolicRegressor, self).__init__( 155 num_threads=num_threads, 156 time_limit=time_limit, 157 iter_limit=iter_limit, 158 precision=precision, 159 problem=problem, 160 feature_probs=feature_probs, 161 random_state=random_state, 162 verbose=verbose, 163 metric=metric, 164 transformation=transformation, 165 algo_settings=algo_settings, 166 code_settings=code_settings, 167 population_settings=population_settings, 168 init_const_settings=init_const_settings, 169 const_settings=const_settings, 170 target_clip=target_clip, 171 class_weight=None, 172 cv_params=cv_params, 173 warm_start=warm_start 174 )
176 def fit(self, X, y, sample_weight=None, check_input=True): 177 """ 178 Fit the symbolic models according to the given training data. 179 180 Parameters 181 ---------- 182 X : array-like of shape (n_samples, n_features) 183 Training vector, where `n_samples` is the number of samples and 184 `n_features` is the number of features. 185 186 y : array-like of shape (n_samples,) 187 Target vector relative to X. 188 189 sample_weight : array-like of shape (n_samples,) default=None 190 Array of weights that are assigned to individual samples. 191 If not provided, then each sample is given unit weight. 192 193 check_input : bool, default=True 194 Allow to bypass several input checking. 195 Don't use this parameter unless you know what you're doing. 196 197 Returns 198 ------- 199 self 200 Fitted estimator. 201 """ 202 203 super(SymbolicRegressor, self).fit(X, y, sample_weight=sample_weight, check_input=check_input) 204 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 andn_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.
206 def predict(self, X, id=None, check_input=True, use_parsed_model=True): 207 """ 208 Predict regression target for X. 209 210 Parameters 211 ---------- 212 X : array-like of shape (n_samples, n_features) 213 The input samples. 214 215 id : int 216 Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model. 217 218 check_input : bool, default=True 219 Allow to bypass several input checking. 220 Don't use this parameter unless you know what you're doing. 221 222 Returns 223 ------- 224 y : ndarray of shape (n_samples,) or (n_samples, n_outputs) 225 The predicted values. 226 """ 227 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.
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 aset_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
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 aset_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
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 aset_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
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 : str or array of shape (n_features,), default='xicor' 53 The probability that a mutation will select a feature. 54 If None then the features are selected with equal probability. 55 If 'xicor' then the probabilities are deriveded from xicor corelation coefficient https://doi.org/10.1080/01621459.2020.1758115 56 57 random_state : int, default=0 58 Random generator seed. If 0 then random generator will be initialized by system time. 59 60 verbose : int, default=0 61 Controls the verbosity when fitting and predicting. 62 63 metric : str, default='LogLoss' 64 Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'} 65 66 transformation : str, default='LOGISTIC' 67 Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'} 68 69 algo_settings : dict, default = None 70 If not defined SymbolicSolver.ALGO_SETTINGS is used. 71 ```python 72 algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16} 73 ``` 74 - 'neighbours_count' : (int) Number tested neighbours in each iteration 75 - 'alpha' : (float) Score worsening limit for a iteration 76 - 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1 77 - 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating 78 - 'sample_size : (int) Number of batches of sample used to calculate the score during training 79 80 code_settings : dict, default = None 81 If not defined SymbolicSolver.CODE_SETTINGS is used. 82 ```python 83 code_settings = {'min_size': 32, 'max_size':32, 'const_size':8} 84 ``` 85 - 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0. 86 - 'min_size': (int) Minimum allowed equation size(as a linear program). 87 - 'max_size' : (int) Maximum allowed equation size(as a linear program). 88 89 population_settings : dict, default = None 90 If not defined SymbolicSolver.POPULATION_SETTINGS is used. 91 ```python 92 population_settings = {'size': 64, 'tournament':4} 93 ``` 94 - 'size' : (int) Number of individuals in the population. 95 - 'tournament' : (int) Tournament selection. 96 97 init_const_settings : dict, default = None 98 If not defined SymbolicSolver.INIT_CONST_SETTINGS is used. 99 ```python 100 init_const_settings = {'const_min':-1.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []} 101 ``` 102 - 'const_min' : (float) Lower range for initializing constants. 103 - 'const_max' : (float) Upper range for initializing constants. 104 - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization. 105 - 'predefined_const_set' : (array of floats) Predefined constants used during initialization. 106 107 const_settings : dict, default = None 108 If not defined SymbolicSolver.CONST_SETTINGS is used. 109 ```python 110 const_settings = {'const_min':-LARGE_FLOAT, 'const_max':LARGE_FLOAT, 'predefined_const_prob':0.0, 'predefined_const_set': []} 111 ``` 112 - 'const_min' : (float) Lower range for constants used in equations. 113 - 'const_max' : (float) Upper range for constants used in equations. 114 - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation). 115 - 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation). 116 117 target_clip : array, default = None 118 Array of two float values clip_min and clip_max. 119 If not defined SymbolicSolver.CLASSIFICATION_TARGET_CLIP is used. 120 ```python 121 target_clip=[3e-7, 1.0-3e-7] 122 ``` 123 class_weight : dict or 'balanced', default=None 124 Weights associated with classes in the form ``{class_label: weight}``. 125 If not given, all classes are supposed to have weight one. 126 127 The "balanced" mode uses the values of y to automatically adjust 128 weights inversely proportional to class frequencies in the input data 129 as ``n_samples / (n_classes * np.bincount(y))``. 130 131 Note that these weights will be multiplied with sample_weight (passed 132 through the fit method) if sample_weight is specified. 133 134 cv_params : dict, default = None 135 If not defined SymbolicSolver.CLASSIFICATION_CV_PARAMS is used. 136 ```python 137 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)} 138 ``` 139 - 'n' : (int) Crossvalidate n top models 140 - 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method 141 - select : (str) Best model selection method choose from 'mean'or 'median' 142 - opt_params : (dict) Parameters passed to scipy.optimize.minimize method 143 - opt_metric : (make_scorer) Scoring method 144 145 warm_start : bool, default=False 146 If True, then the solver will be reused for the next call of fit. 147 """ 148 149 def __init__(self, 150 num_threads: int = 1, 151 time_limit: float = 5.0, 152 iter_limit: int = 0, 153 precision: str = 'f32', 154 problem = 'math', 155 feature_probs = 'xicor', 156 random_state: int = 0, 157 verbose: int = 0, 158 metric: str = 'LogLoss', 159 transformation: str = 'LOGISTIC', 160 algo_settings = None, 161 code_settings = None, 162 population_settings = None, 163 init_const_settings = None, 164 const_settings = None, 165 target_clip = None, 166 class_weight = None, 167 cv_params = None, 168 warm_start : bool = False 169 ): 170 171 super(NonlinearLogisticRegressor, self).__init__( 172 num_threads=num_threads, 173 time_limit=time_limit, 174 iter_limit=iter_limit, 175 precision=precision, 176 problem=problem, 177 feature_probs=feature_probs, 178 random_state=random_state, 179 verbose=verbose, 180 metric=metric, 181 transformation=transformation, 182 algo_settings=algo_settings, 183 code_settings=code_settings, 184 population_settings=population_settings, 185 init_const_settings=init_const_settings, 186 const_settings=const_settings, 187 target_clip=target_clip, 188 class_weight=class_weight, 189 cv_params=cv_params, 190 warm_start=warm_start 191 ) 192 193 def fit(self, X, y, sample_weight=None, check_input=True): 194 """ 195 Fit the symbolic models according to the given training data. 196 197 Parameters 198 ---------- 199 X : array-like of shape (n_samples, n_features) 200 Training vector, where `n_samples` is the number of samples and 201 `n_features` is the number of features. 202 203 y : array-like of shape (n_samples,) 204 Target vector relative to X. Needs samples of 2 classes. 205 206 sample_weight : array-like of shape (n_samples,) default=None 207 Array of weights that are assigned to individual samples. 208 If not provided, then each sample is given unit weight. 209 210 check_input : bool, default=True 211 Allow to bypass several input checking. 212 Don't use this parameter unless you know what you're doing. 213 214 Returns 215 ------- 216 self 217 Fitted estimator. 218 """ 219 220 if check_input: 221 X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False) 222 check_classification_targets(y) 223 enc = LabelEncoder() 224 y_ind = enc.fit_transform(y) 225 self.classes_ = enc.classes_ 226 self.n_classes_ = len(self.classes_) 227 if self.n_classes_ != 2: 228 raise ValueError( 229 "This solver needs samples of 2 classes" 230 " in the data, but the data contains" 231 " %r classes" 232 % self.n_classes_ 233 ) 234 235 self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y) 236 237 super(NonlinearLogisticRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=False) 238 return self 239 240 def predict(self, X, id=None, check_input=True, use_parsed_model=True): 241 """ 242 Predict class for X. 243 244 Parameters 245 ---------- 246 X : array-like of shape (n_samples, n_features) 247 The input samples. 248 249 id : int 250 Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model. 251 252 check_input : bool, default=True 253 Allow to bypass several input checking. 254 Don't use this parameter unless you know what you're doing. 255 256 Returns 257 ------- 258 y : ndarray of shape (n_samples,) 259 The predicted classes. 260 """ 261 preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model) 262 return self.classes_[(preds > 0.5).astype(int)] 263 264 def predict_proba(self, X, id=None, check_input=True): 265 """ 266 Predict class probabilities for X. 267 268 Parameters 269 ---------- 270 X : array-like of shape (n_samples, n_features) 271 272 check_input : bool, default=True 273 Allow to bypass several input checking. 274 Don't use this parameter unless you know what you're doing. 275 276 Returns 277 ------- 278 T : ndarray of shape (n_samples, n_classes) 279 The class probabilities of the input samples. The order of the 280 classes corresponds to that in the attribute :term:`classes_`. 281 """ 282 preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input) 283 proba = numpy.vstack([1 - preds, preds]).T 284 return proba 285 286 def _more_tags(self): 287 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 (str or array of shape (n_features,), default='xicor'): The probability that a mutation will select a feature. If None then the features are selected with equal probability. If 'xicor' then the probabilities are deriveded from xicor corelation coefficient https://doi.org/10.1080/01621459.2020.1758115
- 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.
149 def __init__(self, 150 num_threads: int = 1, 151 time_limit: float = 5.0, 152 iter_limit: int = 0, 153 precision: str = 'f32', 154 problem = 'math', 155 feature_probs = 'xicor', 156 random_state: int = 0, 157 verbose: int = 0, 158 metric: str = 'LogLoss', 159 transformation: str = 'LOGISTIC', 160 algo_settings = None, 161 code_settings = None, 162 population_settings = None, 163 init_const_settings = None, 164 const_settings = None, 165 target_clip = None, 166 class_weight = None, 167 cv_params = None, 168 warm_start : bool = False 169 ): 170 171 super(NonlinearLogisticRegressor, self).__init__( 172 num_threads=num_threads, 173 time_limit=time_limit, 174 iter_limit=iter_limit, 175 precision=precision, 176 problem=problem, 177 feature_probs=feature_probs, 178 random_state=random_state, 179 verbose=verbose, 180 metric=metric, 181 transformation=transformation, 182 algo_settings=algo_settings, 183 code_settings=code_settings, 184 population_settings=population_settings, 185 init_const_settings=init_const_settings, 186 const_settings=const_settings, 187 target_clip=target_clip, 188 class_weight=class_weight, 189 cv_params=cv_params, 190 warm_start=warm_start 191 )
193 def fit(self, X, y, sample_weight=None, check_input=True): 194 """ 195 Fit the symbolic models according to the given training data. 196 197 Parameters 198 ---------- 199 X : array-like of shape (n_samples, n_features) 200 Training vector, where `n_samples` is the number of samples and 201 `n_features` is the number of features. 202 203 y : array-like of shape (n_samples,) 204 Target vector relative to X. Needs samples of 2 classes. 205 206 sample_weight : array-like of shape (n_samples,) default=None 207 Array of weights that are assigned to individual samples. 208 If not provided, then each sample is given unit weight. 209 210 check_input : bool, default=True 211 Allow to bypass several input checking. 212 Don't use this parameter unless you know what you're doing. 213 214 Returns 215 ------- 216 self 217 Fitted estimator. 218 """ 219 220 if check_input: 221 X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False) 222 check_classification_targets(y) 223 enc = LabelEncoder() 224 y_ind = enc.fit_transform(y) 225 self.classes_ = enc.classes_ 226 self.n_classes_ = len(self.classes_) 227 if self.n_classes_ != 2: 228 raise ValueError( 229 "This solver needs samples of 2 classes" 230 " in the data, but the data contains" 231 " %r classes" 232 % self.n_classes_ 233 ) 234 235 self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y) 236 237 super(NonlinearLogisticRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=False) 238 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 andn_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.
240 def predict(self, X, id=None, check_input=True, use_parsed_model=True): 241 """ 242 Predict class for X. 243 244 Parameters 245 ---------- 246 X : array-like of shape (n_samples, n_features) 247 The input samples. 248 249 id : int 250 Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model. 251 252 check_input : bool, default=True 253 Allow to bypass several input checking. 254 Don't use this parameter unless you know what you're doing. 255 256 Returns 257 ------- 258 y : ndarray of shape (n_samples,) 259 The predicted classes. 260 """ 261 preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model) 262 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.
264 def predict_proba(self, X, id=None, check_input=True): 265 """ 266 Predict class probabilities for X. 267 268 Parameters 269 ---------- 270 X : array-like of shape (n_samples, n_features) 271 272 check_input : bool, default=True 273 Allow to bypass several input checking. 274 Don't use this parameter unless you know what you're doing. 275 276 Returns 277 ------- 278 T : ndarray of shape (n_samples, n_classes) 279 The class probabilities of the input samples. The order of the 280 classes corresponds to that in the attribute :term:`classes_`. 281 """ 282 preds = super(NonlinearLogisticRegressor, self).predict(X, id, check_input=check_input) 283 proba = numpy.vstack([1 - preds, preds]).T 284 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_
.
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 aset_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
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 aset_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
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 aset_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
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 aset_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
289class SymbolicClassifier(OneVsRestClassifier): 290 """ 291 OVR multiclass symbolic classificator 292 293 Parameters 294 ---------- 295 estimator : NonlinearLogisticRegressor 296 Instance of NonlinearLogisticRegressor class. 297 """ 298 def __init__(self, estimator=NonlinearLogisticRegressor()): 299 super().__init__(estimator=estimator) 300 301 def fit(self, X, y): 302 """ 303 Fit the symbolic models according to the given training data. 304 305 Parameters 306 ---------- 307 X : array-like of shape (n_samples, n_features) 308 Training vector, where `n_samples` is the number of samples and 309 `n_features` is the number of features. Should be in the range [0, 1]. 310 311 y : array-like of shape (n_samples,) 312 Target vector relative to X. 313 314 Returns 315 ------- 316 self 317 Fitted estimator. 318 """ 319 320 super().fit(X, y) 321 return self 322 323 def predict(self, X): 324 """ 325 Predict class for X. 326 327 Parameters 328 ---------- 329 X : array-like of shape (n_samples, n_features) 330 The input samples. 331 332 Returns 333 ------- 334 y : ndarray of shape (n_samples,) 335 The predicted classes. 336 """ 337 return super().predict(X) 338 339 def predict_proba(self, X): 340 """ 341 Predict class probabilities for X. 342 343 Parameters 344 ---------- 345 X : narray-like of shape (n_samples, n_features) 346 347 Returns 348 ------- 349 T : ndarray of shape (n_samples, n_classes) 350 The class probabilities of the input samples. The order of the 351 classes corresponds to that in the attribute :term:`classes_`. 352 """ 353 return super().predict_proba(X)
OVR multiclass symbolic classificator
Parameters
- estimator (NonlinearLogisticRegressor): Instance of NonlinearLogisticRegressor class.
301 def fit(self, X, y): 302 """ 303 Fit the symbolic models according to the given training data. 304 305 Parameters 306 ---------- 307 X : array-like of shape (n_samples, n_features) 308 Training vector, where `n_samples` is the number of samples and 309 `n_features` is the number of features. Should be in the range [0, 1]. 310 311 y : array-like of shape (n_samples,) 312 Target vector relative to X. 313 314 Returns 315 ------- 316 self 317 Fitted estimator. 318 """ 319 320 super().fit(X, y) 321 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 andn_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.
323 def predict(self, X): 324 """ 325 Predict class for X. 326 327 Parameters 328 ---------- 329 X : array-like of shape (n_samples, n_features) 330 The input samples. 331 332 Returns 333 ------- 334 y : ndarray of shape (n_samples,) 335 The predicted classes. 336 """ 337 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.
339 def predict_proba(self, X): 340 """ 341 Predict class probabilities for X. 342 343 Parameters 344 ---------- 345 X : narray-like of shape (n_samples, n_features) 346 347 Returns 348 ------- 349 T : ndarray of shape (n_samples, n_classes) 350 The class probabilities of the input samples. The order of the 351 classes corresponds to that in the attribute :term:`classes_`. 352 """ 353 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_
.
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 aset_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
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 aset_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
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 : str or array of shape (n_features,), default='xicor' 40 The probability that a mutation will select a feature. 41 If None then the features are selected with equal probability. 42 If 'xicor' then the probabilities are deriveded from xicor corelation coefficient https://doi.org/10.1080/01621459.2020.1758115 43 44 random_state : int, default=0 45 Random generator seed. If 0 then random generator will be initialized by system time. 46 47 verbose : int, default=0 48 Controls the verbosity when fitting and predicting. 49 50 metric : str, default='LogLoss' 51 Metric used for evaluating error. Choose from {'MSE', 'MAE', 'MSLE', 'LogLoss'} 52 53 transformation : str, default=None 54 Final transformation for computed value. Choose from { None, 'LOGISTIC', 'ORDINAL'} 55 56 algo_settings : dict, default = None 57 If not defined SymbolicSolver.ALGO_SETTINGS is used. 58 ```python 59 algo_settings = {'neighbours_count':15, 'alpha':0.15, 'beta':0.5, 'pretest_size':1, 'sample_size':16} 60 ``` 61 - 'neighbours_count' : (int) Number tested neighbours in each iteration 62 - 'alpha' : (float) Score worsening limit for a iteration 63 - 'beta' : (float) Tree breadth-wise expanding factor in a range from 0 to 1 64 - 'pretest_size' : (int) Batch count(batch is 64 rows sample) for fast fitness preevaluating 65 - 'sample_size : (int) Number of batches of sample used to calculate the score during training 66 67 code_settings : dict, default = None 68 If not defined SymbolicSolver.CODE_SETTINGS is used. 69 ```python 70 code_settings = {'min_size': 32, 'max_size':32, 'const_size':8} 71 ``` 72 - 'const_size' : (int) Maximum alloved constants in symbolic model, accept also 0. 73 - 'min_size': (int) Minimum allowed equation size(as a linear program). 74 - 'max_size' : (int) Maximum allowed equation size(as a linear program). 75 76 population_settings : dict, default = None 77 If not defined SymbolicSolver.POPULATION_SETTINGS is used. 78 ```python 79 population_settings = {'size': 64, 'tournament':4} 80 ``` 81 - 'size' : (int) Number of individuals in the population. 82 - 'tournament' : (int) Tournament selection. 83 84 init_const_settings : dict, default = None 85 If not defined FuzzyRegressor.INIT_CONST_SETTINGS is used. 86 ```python 87 init_const_settings = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []} 88 ``` 89 - 'const_min' : (float) Lower range for initializing constants. 90 - 'const_max' : (float) Upper range for initializing constants. 91 - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during initialization. 92 - 'predefined_const_set' : (array of floats) Predefined constants used during initialization. 93 94 const_settings : dict, default = None 95 If not defined FuzzyRegressor.CONST_SETTINGS is used. 96 ```python 97 const_settings = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []} 98 ``` 99 - 'const_min' : (float) Lower range for constants used in equations. 100 - 'const_max' : (float) Upper range for constants used in equations. 101 - 'predefined_const_prob': (float) Probability of selecting one of the predefined constants during search process(mutation). 102 - 'predefined_const_set' : (array of floats) Predefined constants used during search process(mutation). 103 104 target_clip : array, default = None 105 Array of two float values clip_min and clip_max. 106 If not defined SymbolicSolver.CLASSIFICATION_TARGET_CLIP is used. 107 ```python 108 target_clip=[3e-7, 1.0-3e-7] 109 ``` 110 class_weight : dict or 'balanced', default=None 111 Weights associated with classes in the form ``{class_label: weight}``. 112 If not given, all classes are supposed to have weight one. 113 114 The "balanced" mode uses the values of y to automatically adjust 115 weights inversely proportional to class frequencies in the input data 116 as ``n_samples / (n_classes * np.bincount(y))``. 117 118 Note that these weights will be multiplied with sample_weight (passed 119 through the fit method) if sample_weight is specified. 120 121 cv_params : dict, default = None 122 If not defined SymbolicSolver.CLASSIFICATION_CV_PARAMS is used. 123 ```python 124 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)} 125 ``` 126 - 'n' : (int) Crossvalidate n top models 127 - 'cv_params' : (dict) Parameters passed to scikit-learn cross_validate method 128 - select : (str) Best model selection method choose from 'mean'or 'median' 129 - opt_params : (dict) Parameters passed to scipy.optimize.minimize method 130 - opt_metric : (make_scorer) Scoring method 131 132 warm_start : bool, default=False 133 If True, then the solver will be reused for the next call of fit. 134 """ 135 136 INIT_CONST_SETTINGS = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []} 137 CONST_SETTINGS = {'const_min':0.0, 'const_max':1.0, 'predefined_const_prob':0.0, 'predefined_const_set': []} 138 139 def __init__(self, 140 num_threads: int = 1, 141 time_limit: float = 5.0, 142 iter_limit: int = 0, 143 precision: str = 'f32', 144 problem = 'fuzzy', 145 feature_probs = 'xicor', 146 random_state: int = 0, 147 verbose: int = 0, 148 metric: str = 'LogLoss', 149 transformation: str = None, 150 algo_settings = None, 151 code_settings = None, 152 population_settings = None, 153 init_const_settings = None, 154 const_settings = None, 155 target_clip = None, 156 class_weight = None, 157 cv_params = None, 158 warm_start : bool = False 159 ): 160 super(FuzzyRegressor, self).__init__( 161 num_threads=num_threads, 162 time_limit=time_limit, 163 iter_limit=iter_limit, 164 precision=precision, 165 problem=problem, 166 feature_probs=feature_probs, 167 random_state=random_state, 168 verbose=verbose, 169 metric=metric, 170 algo_settings=algo_settings, 171 transformation=transformation, 172 code_settings=code_settings, 173 population_settings=population_settings, 174 init_const_settings=init_const_settings, 175 const_settings=const_settings, 176 target_clip=target_clip, 177 class_weight=class_weight, 178 cv_params=cv_params, 179 warm_start=warm_start 180 ) 181 182 def fit(self, X, y, sample_weight=None, check_input=True): 183 """ 184 Fit the symbolic models according to the given training data. 185 186 Parameters 187 ---------- 188 X : array-like of shape (n_samples, n_features) 189 Training vector, where `n_samples` is the number of samples and 190 `n_features` is the number of features. Should be in the range [0, 1]. 191 192 y : array-like of shape (n_samples,) 193 Target vector relative to X. Needs samples of 2 classes. 194 195 sample_weight : array-like of shape (n_samples,) default=None 196 Array of weights that are assigned to individual samples. 197 If not provided, then each sample is given unit weight. 198 199 check_input : bool, default=True 200 Allow to bypass several input checking. 201 Don't use this parameter unless you know what you're doing. 202 203 Returns 204 ------- 205 self 206 Fitted estimator. 207 """ 208 if check_input: 209 X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False) 210 check_classification_targets(y) 211 enc = LabelEncoder() 212 y_ind = enc.fit_transform(y) 213 self.classes_ = enc.classes_ 214 self.n_classes_ = len(self.classes_) 215 if self.n_classes_ != 2: 216 raise ValueError( 217 "This solver needs samples of 2 classes" 218 " in the data, but the data contains" 219 " %r classes" 220 % self.n_classes_ 221 ) 222 223 self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y) 224 225 super(FuzzyRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=check_input) 226 return self 227 228 def predict(self, X, id=None, check_input=True, use_parsed_model=True): 229 """ 230 Predict class for X. 231 232 Parameters 233 ---------- 234 X : array-like of shape (n_samples, n_features) 235 The input samples. 236 237 id : int 238 Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model. 239 240 check_input : bool, default=True 241 Allow to bypass several input checking. 242 Don't use this parameter unless you know what you're doing. 243 244 Returns 245 ------- 246 y : ndarray of shape (n_samples,) 247 The predicted classes. 248 """ 249 preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model) 250 return self.classes_[(preds > 0.5).astype(int)] 251 252 def predict_proba(self, X, id=None, check_input=True): 253 """ 254 Predict class probabilities for X. 255 256 Parameters 257 ---------- 258 X : array-like of shape (n_samples, n_features) 259 260 check_input : bool, default=True 261 Allow to bypass several input checking. 262 Don't use this parameter unless you know what you're doing. 263 264 Returns 265 ------- 266 T : ndarray of shape (n_samples, n_classes) 267 The class probabilities of the input samples. The order of the 268 classes corresponds to that in the attribute :term:`classes_`. 269 """ 270 preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input) 271 proba = numpy.vstack([1 - preds, preds]).T 272 return proba 273 274 def _more_tags(self): 275 return { 276 'binary_only': True, 277 'poor_score':True, # tests from check_estimator dont have fuzzy number type 278 }
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 (str or array of shape (n_features,), default='xicor'): The probability that a mutation will select a feature. If None then the features are selected with equal probability. If 'xicor' then the probabilities are deriveded from xicor corelation coefficient https://doi.org/10.1080/01621459.2020.1758115
- 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.
139 def __init__(self, 140 num_threads: int = 1, 141 time_limit: float = 5.0, 142 iter_limit: int = 0, 143 precision: str = 'f32', 144 problem = 'fuzzy', 145 feature_probs = 'xicor', 146 random_state: int = 0, 147 verbose: int = 0, 148 metric: str = 'LogLoss', 149 transformation: str = None, 150 algo_settings = None, 151 code_settings = None, 152 population_settings = None, 153 init_const_settings = None, 154 const_settings = None, 155 target_clip = None, 156 class_weight = None, 157 cv_params = None, 158 warm_start : bool = False 159 ): 160 super(FuzzyRegressor, self).__init__( 161 num_threads=num_threads, 162 time_limit=time_limit, 163 iter_limit=iter_limit, 164 precision=precision, 165 problem=problem, 166 feature_probs=feature_probs, 167 random_state=random_state, 168 verbose=verbose, 169 metric=metric, 170 algo_settings=algo_settings, 171 transformation=transformation, 172 code_settings=code_settings, 173 population_settings=population_settings, 174 init_const_settings=init_const_settings, 175 const_settings=const_settings, 176 target_clip=target_clip, 177 class_weight=class_weight, 178 cv_params=cv_params, 179 warm_start=warm_start 180 )
182 def fit(self, X, y, sample_weight=None, check_input=True): 183 """ 184 Fit the symbolic models according to the given training data. 185 186 Parameters 187 ---------- 188 X : array-like of shape (n_samples, n_features) 189 Training vector, where `n_samples` is the number of samples and 190 `n_features` is the number of features. Should be in the range [0, 1]. 191 192 y : array-like of shape (n_samples,) 193 Target vector relative to X. Needs samples of 2 classes. 194 195 sample_weight : array-like of shape (n_samples,) default=None 196 Array of weights that are assigned to individual samples. 197 If not provided, then each sample is given unit weight. 198 199 check_input : bool, default=True 200 Allow to bypass several input checking. 201 Don't use this parameter unless you know what you're doing. 202 203 Returns 204 ------- 205 self 206 Fitted estimator. 207 """ 208 if check_input: 209 X, y = self._validate_data(X, y, accept_sparse=False, y_numeric=False, multi_output=False) 210 check_classification_targets(y) 211 enc = LabelEncoder() 212 y_ind = enc.fit_transform(y) 213 self.classes_ = enc.classes_ 214 self.n_classes_ = len(self.classes_) 215 if self.n_classes_ != 2: 216 raise ValueError( 217 "This solver needs samples of 2 classes" 218 " in the data, but the data contains" 219 " %r classes" 220 % self.n_classes_ 221 ) 222 223 self.class_weight_ = compute_class_weight(self.class_weight, classes=self.classes_, y=y) 224 225 super(FuzzyRegressor, self).fit(X, y_ind, sample_weight=sample_weight, check_input=check_input) 226 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 andn_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.
228 def predict(self, X, id=None, check_input=True, use_parsed_model=True): 229 """ 230 Predict class for X. 231 232 Parameters 233 ---------- 234 X : array-like of shape (n_samples, n_features) 235 The input samples. 236 237 id : int 238 Model id, default=None. id can be obtained from get_models method. If its None prediction use the best model. 239 240 check_input : bool, default=True 241 Allow to bypass several input checking. 242 Don't use this parameter unless you know what you're doing. 243 244 Returns 245 ------- 246 y : ndarray of shape (n_samples,) 247 The predicted classes. 248 """ 249 preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input, use_parsed_model=use_parsed_model) 250 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.
252 def predict_proba(self, X, id=None, check_input=True): 253 """ 254 Predict class probabilities for X. 255 256 Parameters 257 ---------- 258 X : array-like of shape (n_samples, n_features) 259 260 check_input : bool, default=True 261 Allow to bypass several input checking. 262 Don't use this parameter unless you know what you're doing. 263 264 Returns 265 ------- 266 T : ndarray of shape (n_samples, n_classes) 267 The class probabilities of the input samples. The order of the 268 classes corresponds to that in the attribute :term:`classes_`. 269 """ 270 preds = super(FuzzyRegressor, self).predict(X, id, check_input=check_input) 271 proba = numpy.vstack([1 - preds, preds]).T 272 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_
.
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 aset_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
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 aset_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
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 aset_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
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 aset_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
281class FuzzyClassifier(OneVsRestClassifier): 282 """ 283 Fuzzy multiclass symbolic classificator 284 285 Parameters 286 ---------- 287 estimator : FuzzyRegressor 288 Instance of FuzzyRegressor class. 289 """ 290 def __init__(self, estimator=FuzzyRegressor()): 291 super().__init__(estimator=estimator) 292 293 def fit(self, X, y): 294 """ 295 Fit the symbolic models according to the given training data. 296 297 Parameters 298 ---------- 299 X : array-like of shape (n_samples, n_features) 300 Training vector, where `n_samples` is the number of samples and 301 `n_features` is the number of features. Should be in the range [0, 1]. 302 303 y : array-like of shape (n_samples,) 304 Target vector relative to X. 305 306 Returns 307 ------- 308 self 309 Fitted estimator. 310 """ 311 312 super().fit(X, y) 313 return self 314 315 def predict(self, X): 316 """ 317 Predict class for X. 318 319 Parameters 320 ---------- 321 X : array-like of shape (n_samples, n_features) 322 The input samples. 323 324 Returns 325 ------- 326 y : ndarray of shape (n_samples,) 327 The predicted classes. 328 """ 329 return super().predict(X) 330 331 def predict_proba(self, X): 332 """ 333 Predict class probabilities for X. 334 335 Parameters 336 ---------- 337 X : array-like of shape (n_samples, n_features) 338 339 Returns 340 ------- 341 T : ndarray of shape (n_samples, n_classes) 342 The class probabilities of the input samples. The order of the 343 classes corresponds to that in the attribute :term:`classes_`. 344 """ 345 return super().predict_proba(X) 346 347 def _more_tags(self): 348 return { 349 'poor_score':True, # tests from check_estimator dont have fuzzy number type 350 }
Fuzzy multiclass symbolic classificator
Parameters
- estimator (FuzzyRegressor): Instance of FuzzyRegressor class.
293 def fit(self, X, y): 294 """ 295 Fit the symbolic models according to the given training data. 296 297 Parameters 298 ---------- 299 X : array-like of shape (n_samples, n_features) 300 Training vector, where `n_samples` is the number of samples and 301 `n_features` is the number of features. Should be in the range [0, 1]. 302 303 y : array-like of shape (n_samples,) 304 Target vector relative to X. 305 306 Returns 307 ------- 308 self 309 Fitted estimator. 310 """ 311 312 super().fit(X, y) 313 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 andn_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.
315 def predict(self, X): 316 """ 317 Predict class for X. 318 319 Parameters 320 ---------- 321 X : array-like of shape (n_samples, n_features) 322 The input samples. 323 324 Returns 325 ------- 326 y : ndarray of shape (n_samples,) 327 The predicted classes. 328 """ 329 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.
331 def predict_proba(self, X): 332 """ 333 Predict class probabilities for X. 334 335 Parameters 336 ---------- 337 X : array-like of shape (n_samples, n_features) 338 339 Returns 340 ------- 341 T : ndarray of shape (n_samples, n_classes) 342 The class probabilities of the input samples. The order of the 343 classes corresponds to that in the attribute :term:`classes_`. 344 """ 345 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_
.
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 aset_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
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 aset_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
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.
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 andn_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.
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.
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 aset_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
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 aset_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
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 aset_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
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.
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 andn_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.
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.
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_
.
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 aset_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
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 aset_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
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 aset_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
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 aset_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
445def Xicor(X : numpy.ndarray, Y:numpy.ndarray): 446 """ 447 Xicor corelation coefficient. 448 449 This function computes the xi coefficient between two vectors x and y. 450 https://doi.org/10.1080/01621459.2020.1758115 451 452 Parameters 453 ---------- 454 X : array-like input vector x 455 456 Y : array-like input vector y 457 458 Returns 459 ------- 460 xi : float 461 """ 462 if X.ndim != 1: 463 X = numpy.ravel(X) 464 if Y.ndim != 1: 465 Y = numpy.ravel(Y) 466 if len(X) != len(Y): 467 raise ValueError("X and Y must be same size") 468 precision = numpy.float32 469 if X.dtype == Y.dtype and X.dtype == numpy.float64: 470 precision = numpy.float64 471 if not X.flags['C_CONTIGUOUS'] or X.dtype != precision: 472 X = numpy.ascontiguousarray(X.astype(precision)) 473 if not Y.flags['C_CONTIGUOUS'] or Y.dtype != precision: 474 Y = numpy.ascontiguousarray(Y.astype(precision)) 475 if precision == numpy.float32: 476 return Xicor32(X, Y, len(X)) 477 return Xicor64(X, Y, len(X))
Xicor corelation coefficient.
This function computes the xi coefficient between two vectors x and y. https://doi.org/10.1080/01621459.2020.1758115
Parameters
X (array-like input vector x):
Y (array-like input vector y):
Returns
- xi (float):