evorbf.helpers package¶
evorbf.helpers.center_finder module¶
- class evorbf.helpers.center_finder.CenterFinder(seed=None, **params)[source]¶
Bases:
abc.ABCAbstract base class for center-finding strategies.
- class evorbf.helpers.center_finder.DbscanFinder(eps=0.75, seed=None, **params)[source]¶
Bases:
evorbf.helpers.center_finder.CenterFinderUses DBSCAN clustering to determine the centers.
- class evorbf.helpers.center_finder.KMeansFinder(n_centers=10, seed=None, **params)[source]¶
Bases:
evorbf.helpers.center_finder.CenterFinderUses k-means clustering to determine the centers.
- class evorbf.helpers.center_finder.MeanShiftFinder(bandwidth=2.5, seed=None, **params)[source]¶
Bases:
evorbf.helpers.center_finder.CenterFinderUses Mean Shift clustering to determine the centers.
- class evorbf.helpers.center_finder.RandomFinder(n_centers=10, seed=None, **params)[source]¶
Bases:
evorbf.helpers.center_finder.CenterFinderRandomly selects centers from the input data.
evorbf.helpers.kernel module¶
- class evorbf.helpers.kernel.GaussianKernel(sigma=1.0)[source]¶
Bases:
evorbf.helpers.kernel.KernelGaussian radial basis function kernel.
- class evorbf.helpers.kernel.InverseMultiquadricKernel(sigma=1.0)[source]¶
Bases:
evorbf.helpers.kernel.KernelInverse multiquadric radial basis function kernel.
- class evorbf.helpers.kernel.Kernel(**params)[source]¶
Bases:
abc.ABCAbstract base class for kernel radial basis functions.
- abstract compute(x, c)[source]¶
Compute the RBF kernel value between x and c.
- Parameters
x – Input data point(s), shape [n_samples, n_features] or [n_features].
c – Center, shape [n_features].
- Returns
RBF kernel value(s), scalar or array depending on x.
- class evorbf.helpers.kernel.LinearKernel(**params)[source]¶
Bases:
evorbf.helpers.kernel.KernelLinear radial basis function kernel.
- class evorbf.helpers.kernel.MultiquadricKernel(sigma=1.0)[source]¶
Bases:
evorbf.helpers.kernel.KernelMultiquadric radial basis function kernel.
evorbf.helpers.metrics module¶
- evorbf.helpers.metrics.get_all_classification_metrics()[source]¶
Gets a dictionary of all supported classification metrics.
This function returns a dictionary where keys are metric names and values are their optimization types (“min” or “max”).
- Returns
A dictionary containing all supported classification metrics.
- Return type
dict
- evorbf.helpers.metrics.get_all_regression_metrics()[source]¶
Gets a dictionary of all supported regression metrics.
This function returns a dictionary where keys are metric names and values are their optimization types (“min” or “max”).
- Returns
A dictionary containing all supported regression metrics.
- Return type
dict
- evorbf.helpers.metrics.get_metric_sklearn(task='classification', metric_names=None)[source]¶
Creates a dictionary of scorers for scikit-learn cross-validation.
This function takes the task type (classification or regression) and a list of metric names. It creates an appropriate metrics instance (ClassificationMetric or RegressionMetric) and iterates through the provided metric names. For each metric name, it checks if it exists in the metrics instance and retrieves the corresponding method. Finally, it uses make_scorer to convert the method to a scorer and adds it to a dictionary.
- Parameters
task (str, optional) – The task type, either “classification” or “regression”. Defaults to “classification”.
metric_names (list, optional) – A list of metric names. Defaults to None.
- Returns
A dictionary of scorers for scikit-learn cross-validation.
- Return type
dict
- evorbf.helpers.metrics.get_metrics(problem, y_true, y_pred, metrics=None, testcase='test')[source]¶
Calculates metrics for regression or classification tasks.
This function takes the true labels (y_true), predicted labels (y_pred), problem type (regression or classification), a dictionary or list of metrics to calculate, and an optional test case name. It returns a dictionary containing the calculated metrics with descriptive names.
- Parameters
problem (str) – The type of problem, either “regression” or “classification”.
y_true (array-like) – The true labels.
y_pred (array-like) – The predicted labels.
metrics (dict or list, optional) – A dictionary or list of metrics to calculate. Defaults to None.
testcase (str, optional) – An optional test case name to prepend to the metric names. Defaults to “test”.
- Returns
A dictionary containing the calculated metrics with descriptive names.
- Return type
dict
- Raises
ValueError – If the metrics parameter is not a list or dictionary.
evorbf.helpers.preprocessor module¶
- class evorbf.helpers.preprocessor.Data(X=None, y=None, name='Unknown')[source]¶
Bases:
objectThe structure of our supported Data class
- Parameters
X (np.ndarray) – The features of your data
y (np.ndarray) – The labels of your data
- SUPPORT = {'scaler': ['standard', 'minmax', 'max-abs', 'log1p', 'loge', 'sqrt', 'sinh-arc-sinh', 'robust', 'box-cox', 'yeo-johnson']}¶
- class evorbf.helpers.preprocessor.FeatureEngineering[source]¶
Bases:
objectA class for performing custom feature engineering on numeric datasets.
- create_threshold_binary_features(X, threshold)[source]¶
Add binary indicator columns to mark values below a given threshold. Each original column is followed by a new column indicating whether each value is below the threshold (1 if True, 0 otherwise).
- Parameters
X (numpy.ndarray) – The input 2D matrix of shape (n_samples, n_features).
threshold (float) – The threshold value used to determine binary flags.
- Returns
A new 2D matrix of shape (n_samples, 2 * n_features), where each original column is followed by its binary indicator column.
- Return type
numpy.ndarray
- Raises
ValueError – If X is not a NumPy array or not 2D. If threshold is not a numeric type.
- class evorbf.helpers.preprocessor.LabelEncoder[source]¶
Bases:
objectEncode categorical labels as integer indices and decode them back.
This class maps unique categorical labels to integers from 0 to n_classes - 1.
- fit(y)[source]¶
Fit the encoder by finding unique labels in the input data.
- Parameters
y (array-like) – Input labels.
- Returns
self – Fitted LabelEncoder instance.
- Return type
- fit_transform(y)[source]¶
Fit the encoder and transform labels in one step.
- Parameters
y (array-like of shape (n_samples,)) – Input labels.
- Returns
Encoded integer labels.
- Return type
np.ndarray
- class evorbf.helpers.preprocessor.TimeSeriesDifferencer(interval=1)[source]¶
Bases:
objectA class for applying and reversing differencing on time series data.
Differencing helps remove trends and seasonality from time series for better modeling.
- difference(X)[source]¶
Apply differencing to the input time series.
- Parameters
X (array-like) – The original time series data.
- Returns
The differenced time series of length (len(X) - interval).
- Return type
np.ndarray
- inverse_difference(diff_data)[source]¶
Reverse the differencing transformation using the stored original data.
- Parameters
diff_data (array-like) – The differenced data to invert.
- Returns
The reconstructed original data (excluding the first interval values).
- Return type
np.ndarray
- Raises
ValueError – If the original data is not available.
evorbf.helpers.scaler module¶
- class evorbf.helpers.scaler.BoxCoxScaler(lmbda=None)[source]¶
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixin
- class evorbf.helpers.scaler.DataTransformer(scaling_methods=('standard',), list_dict_paras=None)[source]¶
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixinThe class is used to transform data using different scaling techniques.
- Parameters
scaling_methods (str, tuple, list, or np.ndarray) – The name of the scaler you want to use. Supported scaler names are: ‘standard’, ‘minmax’, ‘max-abs’, ‘log1p’, ‘loge’, ‘sqrt’, ‘sinh-arc-sinh’, ‘robust’, ‘box-cox’, ‘yeo-johnson’.
list_dict_paras (dict or list of dict) – The parameters for the scaler. If you have only one scaler, please use a dict. Otherwise, please use a list of dict.
- SUPPORTED_SCALERS = {'box-cox': <class 'evorbf.helpers.scaler.BoxCoxScaler'>, 'log1p': <class 'evorbf.helpers.scaler.Log1pScaler'>, 'loge': <class 'evorbf.helpers.scaler.LogeScaler'>, 'max-abs': <class 'sklearn.preprocessing._data.MaxAbsScaler'>, 'minmax': <class 'sklearn.preprocessing._data.MinMaxScaler'>, 'robust': <class 'sklearn.preprocessing._data.RobustScaler'>, 'sinh-arc-sinh': <class 'evorbf.helpers.scaler.SinhArcSinhScaler'>, 'sqrt': <class 'evorbf.helpers.scaler.SqrtScaler'>, 'standard': <class 'sklearn.preprocessing._data.StandardScaler'>, 'yeo-johnson': <class 'evorbf.helpers.scaler.YeoJohnsonScaler'>}¶
- fit(X, y=None)[source]¶
Fit the sequence of scalers on the data.
- Parameters
X (array-like of shape (n_samples, n_features)) – The input data.
y (Ignored) – Not used, exists for compatibility with sklearn’s pipeline.
- Returns
self – Fitted transformer.
- Return type
object
- class evorbf.helpers.scaler.Log1pScaler[source]¶
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixin
- class evorbf.helpers.scaler.LogeScaler[source]¶
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixin
- class evorbf.helpers.scaler.ObjectiveScaler(obj_name='sigmoid', ohe_scaler=None)[source]¶
Bases:
objectFor label scaler in classification (binary and multiple classification)
- class evorbf.helpers.scaler.OneHotEncoder[source]¶
Bases:
objectA simple implementation of one-hot encoding for 1D categorical data.
- categories_¶
Sorted array of unique categories fitted from the input data.
- Type
np.ndarray
- fit(X)[source]¶
Fit the encoder to the unique categories in X.
- Parameters
X (array-like) – 1D array of categorical values.
- Returns
Fitted OneHotEncoder instance.
- Return type
self
- fit_transform(X)[source]¶
Fit the encoder to X and transform X.
- Parameters
X (array-like) – 1D array of categorical values.
- Returns
One-hot encoded array of shape (n_samples, n_categories).
- Return type
np.ndarray
- inverse_transform(one_hot)[source]¶
Convert one-hot encoded data back to original categories.
- Parameters
one_hot (np.ndarray) – 2D array of one-hot encoded data.
- Returns
1D array of original categorical values.
- Return type
np.ndarray
- Raises
ValueError – If the encoder has not been fitted or shape mismatch occurs.
- transform(X)[source]¶
Transform input data into one-hot encoded format.
- Parameters
X (array-like) – 1D array of categorical values.
- Returns
One-hot encoded array of shape (n_samples, n_categories).
- Return type
np.ndarray
- Raises
ValueError – If the encoder has not been fitted or unknown category is found.
- class evorbf.helpers.scaler.SinhArcSinhScaler(epsilon=0.1, delta=1.0)[source]¶
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixin