intelelm.utils package

intelelm.utils.activation module

intelelm.utils.activation.celu(x, alpha=1.0)[source]
intelelm.utils.activation.elu(x, alpha=1)[source]
intelelm.utils.activation.gelu(x, alpha=0.044715)[source]
intelelm.utils.activation.hard_shrink(x, alpha=0.5)[source]
intelelm.utils.activation.hard_sigmoid(x, lower=- 2.5, upper=2.5)[source]
intelelm.utils.activation.hard_swish(x, lower=- 3.0, upper=3.0)[source]
intelelm.utils.activation.hard_tanh(x, lower=- 1.0, upper=1.0)[source]
intelelm.utils.activation.leaky_relu(x, alpha=0.01)[source]
intelelm.utils.activation.log_sigmoid(x)[source]
intelelm.utils.activation.log_softmax(x)[source]
intelelm.utils.activation.mish(x, beta=1.0)[source]
intelelm.utils.activation.prelu(x, alpha=0.5)[source]
intelelm.utils.activation.relu(x)[source]
intelelm.utils.activation.rrelu(x, lower=0.125, upper=0.3333333333333333)[source]
intelelm.utils.activation.selu(x, alpha=1.67326324, scale=1.05070098)[source]
intelelm.utils.activation.sigmoid(x)[source]
intelelm.utils.activation.silu(x)
intelelm.utils.activation.soft_plus(x, beta=1.0)[source]
intelelm.utils.activation.soft_shrink(x, alpha=0.5)[source]
intelelm.utils.activation.soft_sign(x)[source]
intelelm.utils.activation.softmax(x)[source]
intelelm.utils.activation.softmin(x)[source]
intelelm.utils.activation.swish(x)[source]
intelelm.utils.activation.tanh(x)[source]
intelelm.utils.activation.tanh_shrink(x)[source]

intelelm.utils.data_loader module

class intelelm.utils.data_loader.Data(X=None, y=None, name='Unknown')[source]

Bases: object

The 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']}
static encode_label(y)[source]
static scale(X, scaling_methods=('standard',), list_dict_paras=None)[source]
set_train_test(X_train=None, y_train=None, X_test=None, y_test=None)[source]

Function use to set your own X_train, y_train, X_test, y_test in case you don’t want to use our split function

Parameters
  • X_train (np.ndarray) –

  • y_train (np.ndarray) –

  • X_test (np.ndarray) –

  • y_test (np.ndarray) –

split_train_test(test_size=0.2, train_size=None, random_state=41, shuffle=True, stratify=None, inplace=True)[source]

The wrapper of the split_train_test function in scikit-learn library.

intelelm.utils.data_loader.get_dataset(dataset_name)[source]

Helper function to retrieve the data

Parameters

dataset_name (str) – Name of the dataset

Returns

data – The instance of Data class, that hold X and y variables.

Return type

Data

intelelm.utils.encoder module

class intelelm.utils.encoder.LabelEncoder[source]

Bases: object

Encode categorical features as integer labels.

fit(y)[source]

Fit label encoder to a given set of labels.

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,)

inverse_transform(y)[source]

Transform integer labels to original labels.

yarray-like

Encoded integer labels.

original_labelsarray-like

Original labels.

transform(y)[source]

Transform labels to encoded integer labels.

yarray-like

Labels to encode.

encoded_labelsarray-like

Encoded integer labels.

class intelelm.utils.encoder.ObjectiveScaler(obj_name='sigmoid', ohe_scaler=None)[source]

Bases: object

For label scaler in classification (binary and multiple classification)

inverse_transform(data)[source]
transform(data)[source]

intelelm.utils.evaluator module

intelelm.utils.evaluator.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

intelelm.utils.evaluator.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

intelelm.utils.evaluator.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

intelelm.utils.evaluator.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.

intelelm.utils.scaler module

class intelelm.utils.scaler.BoxCoxScaler(lmbda=None)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

fit(X, y=None)[source]
inverse_transform(X)[source]
transform(X)[source]
class intelelm.utils.scaler.DataTransformer(scaling_methods=('standard',), list_dict_paras=None)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

Applies a sequence of scaling transformations to data.

This transformer enables applying multiple scaling techniques sequentially. It supports a variety of scaling methods, including standardization, normalization, logarithmic transformations, and more.

Parameters
  • scaling_methods (str, tuple, list, or np.ndarray) – The names of scaling methods to apply.

  • list_dict_paras (list of dict, optional) – A list of dictionaries containing parameters for each scaling method.

scalers

A list of scaler instances.

Type

list

fit(X, y=None)[source]

Fits the scaler instances to the input data.

transform(X)[source]

Applies the scaling transformations to the input data.

inverse_transform(X)[source]

Applies the inverse scaling transformations to the input data.

SUPPORTED_SCALERS = {'box-cox': <class 'intelelm.utils.scaler.BoxCoxScaler'>, 'log1p': <class 'intelelm.utils.scaler.Log1pScaler'>, 'loge': <class 'intelelm.utils.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 'intelelm.utils.scaler.SinhArcSinhScaler'>, 'sqrt': <class 'intelelm.utils.scaler.SqrtScaler'>, 'standard': <class 'sklearn.preprocessing._data.StandardScaler'>, 'yeo-johnson': <class 'intelelm.utils.scaler.YeoJohnsonScaler'>}
fit(X, y=None)[source]
inverse_transform(X)[source]
transform(X)[source]
class intelelm.utils.scaler.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 intelelm.utils.scaler.Log1pScaler[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

fit(X, y=None)[source]
inverse_transform(X)[source]
transform(X)[source]
class intelelm.utils.scaler.LogeScaler[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

fit(X, y=None)[source]
inverse_transform(X)[source]
transform(X)[source]
class intelelm.utils.scaler.SinhArcSinhScaler(epsilon=0.1, delta=1.0)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

fit(X, y=None)[source]
inverse_transform(X)[source]
transform(X)[source]
class intelelm.utils.scaler.SqrtScaler[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

fit(X, y=None)[source]
inverse_transform(X)[source]
transform(X)[source]
class intelelm.utils.scaler.TimeSeriesDifferencer(interval=1)[source]

Bases: object

difference(X)[source]
inverse_difference(diff_data)[source]
class intelelm.utils.scaler.YeoJohnsonScaler(lmbda=None)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

fit(X, y=None)[source]
inverse_transform(X)[source]
transform(X)[source]

intelelm.utils.validator module

intelelm.utils.validator.check_bool(name: str, value: bool, bound=(True, False))[source]

Checks if a value is a boolean and optionally verifies it matches a specified bound.

Parameters
  • name (str) – The name of the variable being checked.

  • value (bool) – The value to check.

  • bound (tuple, optional) – A tuple of allowed boolean values.

Returns

The validated boolean value.

Return type

bool

Raises

ValueError – If the value is not a boolean or not in the bound (if provided).

intelelm.utils.validator.check_float(name: str, value: int, bound=None)[source]

Checks if a value is a float and optionally verifies it falls within a specified bound.

Parameters
  • name (str) – The name of the variable being checked.

  • value (int or float) – The value to check.

  • bound (tuple, optional) – A tuple representing the lower and upper bound (inclusive).

Returns

The validated float value.

Return type

float

Raises

ValueError – If the value is not a float or falls outside the bound (if provided).

intelelm.utils.validator.check_int(name: str, value: int, bound=None)[source]

Checks if a value is an integer and optionally verifies it falls within a specified bound.

Parameters
  • name (str) – The name of the variable being checked.

  • value (int or float) – The value to check.

  • bound (tuple, optional) – A tuple representing the lower and upper bound (inclusive).

Returns

The validated integer value.

Return type

int

Raises

ValueError – If the value is not an integer or falls outside the bound (if provided).

intelelm.utils.validator.check_str(name: str, value: str, bound=None)[source]

Checks if a value is a string and optionally verifies it exists within a provided list.

Parameters
  • name (str) – The name of the variable being checked.

  • value (str) – The value to check.

  • bound (list, optional) – A list of allowed string values.

Returns

The validated string value.

Return type

str

Raises

ValueError – If the value is not a string or not found in the bound list (if provided).

intelelm.utils.validator.check_tuple_float(name: str, values: tuple, bounds=None)[source]

Checks if a tuple contains only floats or integers and optionally verifies they fall within specified bounds.

Parameters
  • name (str) – The name of the variable being checked.

  • values (tuple) – The tuple of values to check.

  • bounds (list of tuples, optional) – A list of tuples representing lower and upper bounds for each value.

Returns

The validated tuple of floats.

Return type

tuple

Raises

ValueError – If the values are not all floats or integers or do not fall within the specified bounds.

intelelm.utils.validator.check_tuple_int(name: str, values: tuple, bounds=None)[source]

Checks if a tuple contains only integers and optionally verifies they fall within specified bounds.

Parameters
  • name (str) – The name of the variable being checked.

  • values (tuple) – The tuple of values to check.

  • bounds (list of tuples, optional) – A list of tuples representing lower and upper bounds for each value.

Returns

The validated tuple of integers.

Return type

tuple

Raises

ValueError – If the values are not all integers or do not fall within the specified bounds.

intelelm.utils.validator.is_in_bound(value, bound)[source]

Checks if a value falls within a specified numerical bound.

Parameters
  • value (float) – The value to check.

  • bound (tuple) – A tuple representing the lower and upper bound (inclusive for lists).

Returns

True if the value is within the bound, False otherwise.

Return type

bool

Raises

ValueError – If the bound is not a tuple or list.

intelelm.utils.validator.is_str_in_list(value: str, my_list: list)[source]

Checks if a string value exists within a provided list.

Parameters
  • value (str) – The string value to check.

  • my_list (list, optional) – The list of possible values.

Returns

True if the value is in the list, False otherwise.

Return type

bool