metaperceptron.helpers package¶
metaperceptron.helpers.metric_util module¶
- metaperceptron.helpers.metric_util.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
- metaperceptron.helpers.metric_util.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
- metaperceptron.helpers.metric_util.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
- metaperceptron.helpers.metric_util.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.
metaperceptron.helpers.preprocessor module¶
- class metaperceptron.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 metaperceptron.helpers.preprocessor.FeatureEngineering[source]¶
Bases:
object- create_threshold_binary_features(X, threshold)[source]¶
Perform feature engineering to add binary indicator columns for values below the threshold. Add each new column right after the corresponding original column.
Args: X (numpy.ndarray): The input 2D matrix of shape (n_samples, n_features). threshold (float): The threshold value for identifying low values.
Returns: numpy.ndarray: The updated 2D matrix with binary indicator columns.
- class metaperceptron.helpers.preprocessor.LabelEncoder[source]¶
Bases:
objectEncode categorical features as integer labels.
- fit(y)[source]¶
Fit label encoder to a given set of labels.
Parameters:¶
- yarray-like
Labels to encode.
- fit_transform(y)[source]¶
Fit label encoder and return encoded labels.
- Parameters:
y (array-like of shape (n_samples,)) – Target values.
- Returns:
y – Encoded labels.
- Return type:
array-like of shape (n_samples,)
metaperceptron.helpers.scaler_util module¶
- class metaperceptron.helpers.scaler_util.BoxCoxScaler(lmbda=None)[source]¶
Bases:
BaseEstimator,TransformerMixin
- class metaperceptron.helpers.scaler_util.DataTransformer(scaling_methods=('standard',), list_dict_paras=None)[source]¶
Bases:
BaseEstimator,TransformerMixin- SUPPORTED_SCALERS = {'box-cox': <class 'metaperceptron.helpers.scaler_util.BoxCoxScaler'>, 'log1p': <class 'metaperceptron.helpers.scaler_util.Log1pScaler'>, 'loge': <class 'metaperceptron.helpers.scaler_util.LogeScaler'>, 'max-abs': <class 'sklearn.preprocessing._data.MaxAbsScaler'>, 'minmax': <class 'sklearn.preprocessing._data.MinMaxScaler'>, 'robust': <class 'sklearn.preprocessing._data.RobustScaler'>, 'sinh-arc-sinh': <class 'metaperceptron.helpers.scaler_util.SinhArcSinhScaler'>, 'sqrt': <class 'metaperceptron.helpers.scaler_util.SqrtScaler'>, 'standard': <class 'sklearn.preprocessing._data.StandardScaler'>, 'yeo-johnson': <class 'metaperceptron.helpers.scaler_util.YeoJohnsonScaler'>}¶
- class metaperceptron.helpers.scaler_util.Log1pScaler[source]¶
Bases:
BaseEstimator,TransformerMixin
- class metaperceptron.helpers.scaler_util.ObjectiveScaler(obj_name='sigmoid', ohe_scaler=None)[source]¶
Bases:
objectFor label scaler in classification (binary and multiple classification)
- class metaperceptron.helpers.scaler_util.SinhArcSinhScaler(epsilon=0.1, delta=1.0)[source]¶
Bases:
BaseEstimator,TransformerMixin