Models#
Submodules#
models.ada_boost_regressor module#
- class models.ada_boost_regressor.AdaBoostRegressorModel(n_estimators=50, learning_rate=1.0, loss='linear')[source]#
Bases:
models.base.BaseRegressor,sklearn.ensemble._weight_boosting.AdaBoostRegressorAdaBoostRegressorModel is a regression model that combines multiple weak regressors into a strong ensemble model using the AdaBoost algorithm.
- Parameters
n_estimators (int) – The maximum number of estimators at which boosting is terminated. Default is 50.
learning_rate (float) – The learning rate shrinks the contribution of each regressor by the learning_rate. Default is 1.0.
loss (str) – The loss function to use for the individual regressors. Options are ‘linear’, ‘square’ and ‘exponential’. Default is ‘linear’.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the AdaBoostRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the AdaBoostRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the AdaBoostRegressorModel using grid search and cross-validation.
- Parameters
X_train (pd.DataFrame) – The training features.
X_val (pd.DataFrame) – The validation features.
y_train (pd.Series) – The training target.
y_val (pd.Series) – The validation target.
- Returns
The best hyperparameters found during tuning.
- Return type
dict
models.bagging_regressor module#
- class models.bagging_regressor.BaggingRegressorModel(estimator=None, n_estimators=10, random_state=95)[source]#
Bases:
models.base.BaseRegressor,sklearn.ensemble._bagging.BaggingRegressorBaggingRegressorModel is a regression model that fits multiple base regressors on different subsets of the training data and aggregates their predictions to make the final prediction.
- Parameters
estimator (object) – The base estimator to use for fitting on the subsets of the data. If None, the base estimator is a decision tree. Default is None.
n_estimators (int) – The number of base estimators to use. Default is 10.
random_state (int) – The seed used by the random number generator. Default is 95.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the BaggingRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the BaggingRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the BaggingRegressorModel using grid search and cross-validation.
- Parameters
X_train (pd.DataFrame) – The training features.
X_val (pd.DataFrame) – The validation features.
y_train (pd.Series) – The training target.
y_val (pd.Series) – The validation target.
- Returns
The best hyperparameters found during tuning.
- Return type
dict
models.base module#
- class models.base.BaseModelNN[source]#
Bases:
objectBaseModelNN is a base class for neural network models.
- fit_model(X, y, epochs=10, batch_size=32, verbose=1, validation_split=0.2)[source]#
Fits the model to the training data.
- Parameters
X (numpy.ndarray) – The training features.
y (numpy.ndarray) – The training target.
epochs (int) – The number of epochs to train the model. Default is 10.
batch_size (int) – The batch size for training. Default is 32.
verbose (int) – Verbosity mode. 0 - silent, 1 - progress bar, 2 - one line per epoch. Default is 1.
validation_split (float) – The fraction of the training data to use for validation. Default is 0.2.
- load_model()[source]#
Loads the model from a file.
- Parameters
filename (str) – The name of the file to load the model from.
- Returns
The loaded model.
- Return type
tf.keras.Model
- class models.base.BaseRegressor[source]#
Bases:
objectBaseRegressor is a base class for regression models.
- logger#
The logger object for logging messages.
- Type
logging.Logger
- grid_search_cv(model, param_grid, X_train, y_train)[source]#
Performs grid search cross-validation.
- Parameters
model (object) – The model object to tune.
param_grid (dict) – The dictionary of hyperparameter values to search.
X_train (numpy.ndarray) – The training features.
y_train (numpy.ndarray) – The training target.
- Returns
The grid search cross-validation object.
- Return type
sklearn.model_selection.GridSearchCV
- load_model(file_path)[source]#
Loads the model from a file using joblib.
- Parameters
file_path (str) – The path to load the model from.
- log_validation_score(X_val, y_val)[source]#
Logs the validation score.
- Parameters
X_val (numpy.ndarray) – The validation features.
y_val (numpy.ndarray) – The validation target.
- save_model(file_path)[source]#
Saves the model to a file using joblib.
- Parameters
file_path (str) – The path to save the model.
- tune_model(X_train, X_val, y_train, y_val, param_grid, model)[source]#
Tunes the hyperparameters of the model using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
param_grid (dict) – The dictionary of hyperparameter values to search.
model (object) – The model object to tune.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.bayesian_ridge_regressor module#
- class models.bayesian_ridge_regressor.BayesianRidgeRegressorModel(n_iter=300, tol=0.001, alpha_1=1e-06, alpha_2=1e-06, lambda_1=1e-06, lambda_2=1e-06)[source]#
Bases:
models.base.BaseRegressor,sklearn.linear_model._bayes.BayesianRidgeBayesianRidgeRegressorModel is a regression model that performs Bayesian ridge regression.
- Parameters
n_iter (int) – The maximum number of iterations. Default is 300.
tol (float) – The tolerance for stopping criteria. Default is 0.001.
alpha_1 (float) – Hyperparameter for the Gamma distribution prior over the alpha parameter. Default is 1e-06.
alpha_2 (float) – Hyperparameter for the Gamma distribution prior over the alpha parameter. Default is 1e-06.
lambda_1 (float) – Hyperparameter for the Gamma distribution prior over the lambda parameter. Default is 1e-06.
lambda_2 (float) – Hyperparameter for the Gamma distribution prior over the lambda parameter. Default is 1e-06.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the BayesianRidgeRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the BayesianRidgeRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the BayesianRidgeRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
tuple
- Return type
A tuple containing the best estimator and the best parameters found during tuning.
models.cat_boost_regressor module#
- class models.cat_boost_regressor.CatBoostRegressorModel(iterations=500, learning_rate=0.1, depth=6, loss_function='RMSE')[source]#
Bases:
models.base.BaseRegressor,catboost.core.CatBoostRegressorCatBoostRegressorModel is a gradient boosting regression model that uses the CatBoost algorithm.
- Parameters
iterations (int) – The number of boosting iterations. Default is 500.
learning_rate (float) – The learning rate for boosting. Default is 0.1.
depth (int) – The depth of the trees. Default is 6.
loss_function (str) – The loss function to optimize. Default is ‘RMSE’.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the CatBoostRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the CatBoostRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the CatBoostRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.cnn_regressor module#
- class models.cnn_regressor.CNNRegressor(n_features, max_epochs=5, max_batch_size=5, hyperband_iterations=1, patience=5, tuner_epochs=5)[source]#
Bases:
keras_tuner.engine.hypermodel.HyperModel,models.base.BaseModelNNCNNRegressor is a convolutional neural network regression model.
- Parameters
n_features (int) – The number of input features.
max_epochs (int) – The maximum number of epochs for training. Default is 5.
max_batch_size (int) – The maximum batch size for training. Default is 5.
hyperband_iterations (int) – The number of Hyperband iterations. Default is 1.
patience (int) – The number of epochs with no improvement after which training will be stopped. Default is 5.
tuner_epochs (int) – The number of epochs to search for the best hyperparameters. Default is 5.
- build_model()[source]#
Builds the CNN model.
- Returns
The CNN model.
- Return type
keras.models.Sequential
- get_params(deep=True)[source]#
Returns the current hyperparameters of the CNNRegressor model.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the CNNRegressor model.
- Return type
dict
- set_params(**parameters)[source]#
Sets the parameters of the CNNRegressor model.
- Parameters
**parameters (dict, optional) – The parameters to set.
- Return type
self
- tune_model_with_window_cnn(X_train, y_train, X_val, y_val, callbacks=None)[source]#
Tunes the hyperparameters of the CNNRegressor model using Hyperband tuning.
- Parameters
X_train (numpy.ndarray) – The training features.
y_train (numpy.ndarray) – The training target.
X_val (numpy.ndarray) – The validation features.
y_val (numpy.ndarray) – The validation target.
callbacks (list) – List of Keras callbacks. Default is None.
- Returns
A tuple containing the best model, the training history, and the best hyperparameters.
- Return type
tuple
models.decision_tree_regressor module#
- class models.decision_tree_regressor.DecisionTreeRegressorModel(max_depth=None, min_samples_split=2, min_samples_leaf=1, max_features=None)[source]#
Bases:
models.base.BaseRegressor,sklearn.tree._classes.DecisionTreeRegressorDecisionTreeRegressorModel is a regression model based on the decision tree algorithm.
- Parameters
max_depth (int or None) – The maximum depth of the tree. Default is None.
min_samples_split (int) – The minimum number of samples required to split an internal node. Default is 2.
min_samples_leaf (int) – The minimum number of samples required to be at a leaf node. Default is 1.
max_features (int, float, string or None) – The number of features to consider when looking for the best split. Default is None.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the DecisionTreeRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the DecisionTreeRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the DecisionTreeRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.elastic_net_regressor module#
- class models.elastic_net_regressor.ElasticNetRegressorModel(alpha=1.0, l1_ratio=0.5)[source]#
Bases:
models.base.BaseRegressor,sklearn.linear_model._coordinate_descent.ElasticNetElasticNetRegressorModel is a regression model based on the Elastic Net algorithm.
- Parameters
alpha (float) – Constant that multiplies the penalty terms. Default is 1.0.
l1_ratio (float) – The mixing parameter, with 0 <= l1_ratio <= 1. Default is 0.5.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the ElasticNetRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
dict
- Return type
The current hyperparameters of the ElasticNetRegressorModel.
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the ElasticNetRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.extra_trees_regressor module#
- class models.extra_trees_regressor.ExtraTreesRegressorModel(n_estimators=100, max_depth=None, min_samples_split=2)[source]#
Bases:
models.base.BaseRegressor,sklearn.ensemble._forest.ExtraTreesRegressorExtraTreesRegressorModel is a regression model based on the Extra Trees algorithm.
- Parameters
n_estimators (int) – The number of trees in the forest. Default is 100.
max_depth (int or None) – The maximum depth of the tree. Default is None.
min_samples_split (int) – The minimum number of samples required to split an internal node. Default is 2.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the ExtraTreesRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the ExtraTreesRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the ExtraTreesRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.gaussian_regressor module#
- class models.gaussian_regressor.GaussianProcessRegressorModel(kernel=None, alpha=1e-10, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, normalize_y=False, copy_X_train=True)[source]#
Bases:
models.base.BaseRegressor,sklearn.gaussian_process._gpr.GaussianProcessRegressorGaussianProcessRegressorModel is a regression model based on the Gaussian Process algorithm.
- Parameters
kernel (kernel object) – The kernel specifying the covariance function of the Gaussian process. Default is None.
alpha (float) – Value added to the diagonal of the kernel matrix during fitting. Default is 1e-10.
optimizer (string or callable) – The optimizer to use for optimizing the kernel’s parameters. Default is “fmin_l_bfgs_b”.
n_restarts_optimizer (int) – The number of restarts of the optimizer for optimizing the kernel’s parameters. Default is 0.
normalize_y (bool) – Whether to normalize the target values. Default is False.
copy_X_train (bool) – Whether to make a copy of the training data. Default is True.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the GaussianProcessRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the GaussianProcessRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the GaussianProcessRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.gradient_boosting_regressor module#
- class models.gradient_boosting_regressor.GradientBoostingRegressorModel(n_estimators=100, learning_rate=0.1, max_depth=3, min_samples_split=2, min_samples_leaf=1, max_features=None)[source]#
Bases:
models.base.BaseRegressor,sklearn.ensemble._gb.GradientBoostingRegressorGradientBoostingRegressorModel is a regression model based on the Gradient Boosting algorithm.
- Parameters
n_estimators (int) – The number of boosting stages. Default is 100.
learning_rate (float) – The learning rate shrinks the contribution of each tree. Default is 0.1.
max_depth (int or None) – The maximum depth of the tree. Default is 3.
min_samples_split (int) – The minimum number of samples required to split an internal node. Default is 2.
min_samples_leaf (int) – The minimum number of samples required to be at a leaf node. Default is 1.
max_features (int, float, string or None) – The number of features to consider when looking for the best split. Default is None.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the GradientBoostingRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the GradientBoostingRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the GradientBoostingRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.knn_regressor module#
- class models.knn_regressor.KNNRegressorModel(n_neighbors=2, weights='uniform', p=1)[source]#
Bases:
models.base.BaseRegressor,sklearn.neighbors._regression.KNeighborsRegressorKNNRegressorModel is a regression model based on the K-Nearest Neighbors algorithm.
- Parameters
n_neighbors (int) – The number of neighbors to use. Default is 2.
weights (str or callable) – The weight function used in prediction. Default is “uniform”.
p (int) – The power parameter for the Minkowski metric. Default is 1.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the KNNRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the KNNRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the KNNRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
tuple
- Return type
A tuple containing the best estimator and the best parameters found during tuning.
models.lasso_regressor module#
- class models.lasso_regressor.LassoRegressorModel(alpha=1.0)[source]#
Bases:
models.base.BaseRegressor,sklearn.linear_model._coordinate_descent.LassoLassoRegressorModel is a regression model based on the Lasso (L1 regularization) algorithm.
- Parameters
alpha (float) – The regularization strength. Default is 1.0.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the LassoRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the LassoRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the LassoRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
tuple
- Return type
A tuple containing the best estimator and the best parameters found during tuning.
models.lgbm_regressor module#
- class models.lgbm_regressor.LGBMRegressorModel(n_estimators=100, learning_rate=0.1, max_depth=- 1, num_leaves=31, random_state=95)[source]#
Bases:
models.base.BaseRegressor,lightgbm.sklearn.LGBMRegressorLGBMRegressorModel is a regression model based on the LightGBM algorithm.
- Parameters
n_estimators (int) – The number of boosting iterations. Default is 100.
learning_rate (float) – The learning rate of the boosting process. Default is 0.1.
max_depth (int) – The maximum depth of each tree. Default is -1 (unlimited).
num_leaves (int) – The maximum number of leaves in each tree. Default is 31.
random_state (int) – The random seed for reproducible results. Default is 95.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the LGBMRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the LGBMRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the LGBMRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.lstm_regressor module#
- class models.lstm_regressor.LSTMRegressor(n_features, max_epochs=5, max_batch_size=5, hyperband_iterations=1, patience=5, tuner_epochs=5)[source]#
Bases:
keras_tuner.engine.hypermodel.HyperModel,models.base.BaseModelNNLSTMRegressor is a class that implements a Long Short-Term Memory (LSTM) model for regression tasks. It utilizes hyperparameter tuning with the Keras Tuner library to optimize the model’s performance.
- Parameters
n_features (int) – The number of input features.
max_epochs (int) – The maximum number of epochs to train the model. Default is 5.
max_batch_size (int) – The maximum batch size for training the model. Default is 5.
hyperband_iterations (int) – The number of Hyperband iterations. Default is 1.
patience (int) – The number of epochs to wait for improvement in validation loss before early stopping. Default is 5.
tuner_epochs (int) – The number of epochs to train the tuner. Default is 5.
- build_model()[source]#
Builds the LSTM regression model.
- Returns
The constructed LSTM regression model.
- Return type
keras.models.Sequential
- get_params(deep=True)[source]#
Gets the current hyperparameters of the LSTMRegressor.
- Returns
A dictionary of hyperparameter names and their values.
- Return type
dict
- tune_model_with_window_lstm(X_train, y_train, X_val, y_val, callbacks=None)[source]#
Tunes the hyperparameters of the LSTMRegressor using Hyperband tuner.
- Parameters
X_train (array-like) – The training input samples.
y_train (array-like) – The target values for the training samples.
X_val (array-like) – The validation input samples.
y_val (array-like) – The target values for the validation samples.
callbacks (list) – List of Keras callbacks. Default is None.
- Returns
A tuple containing the best model, training history, and best hyperparameters.
- Return type
tuple
models.neural_network_regressor module#
- class models.neural_network_regressor.NeuralNetworkRegressor(n_features, max_epochs=5, max_batch_size=5, hyperband_iterations=1, patience=5, tuner_epochs=5)[source]#
Bases:
keras_tuner.engine.hypermodel.HyperModel,models.base.BaseModelNNNeuralNetworkRegressor is a regression model based on a neural network.
- Parameters
n_features (int) – The number of input features.
max_epochs (int) – The maximum number of epochs to train the model. Default is 5.
max_batch_size (int) – The maximum batch size for training. Default is 5.
hyperband_iterations (int) – The number of Hyperband iterations. Default is 1.
patience (int) – The number of epochs with no improvement after which training will be stopped if early stopping is used. Default is 5.
tuner_epochs (int) – The number of epochs to train the tuner. Default is 5.
- build_model()[source]#
Builds and compiles the neural network model.
- Returns
The compiled neural network model.
- Return type
Sequential
- get_params(deep=True)[source]#
Returns the current hyperparameters of the NeuralNetworkRegressor.
- Returns
A dictionary of the current hyperparameters.
- Return type
dict
- tune_model_with_window_nn(X_train, y_train, X_val, y_val, callbacks=None)[source]#
Tunes the hyperparameters of the NeuralNetworkRegressor using Hyperband tuner.
- Parameters
X_train (array-like) – The training input samples.
y_train (array-like) – The target values for the training samples.
X_val (array-like) – The validation input samples.
y_val (array-like) – The target values for the validation samples.
callbacks (list) – List of Keras callbacks. Default is None.
- Returns
A tuple containing the best model, training history, and best hyperparameters.
- Return type
tuple
models.nu_svr_regressor module#
- class models.nu_svr_regressor.NuSVRRegressorModel(nu=0.5, C=1.0, kernel='rbf', degree=3, gamma='scale', coef0=0.0, shrinking=True, tol=0.001, cache_size=200)[source]#
Bases:
models.base.BaseRegressor,sklearn.svm._classes.NuSVRNuSVRRegressorModel is a regression model based on the Nu-Support Vector Regression algorithm.
- Parameters
nu (float) – An upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. Default is 0.5.
C (float) – The regularization parameter. Default is 1.0.
kernel (str) – The kernel function to use. Can be “linear”, “poly”, “rbf”, or “sigmoid”. Default is “rbf”.
degree (int) – The degree of the polynomial kernel function. Default is 3.
gamma (str or float) – The kernel coefficient for “rbf”, “poly”, and “sigmoid”. Can be “scale”, “auto”, or a float value. Default is “scale”.
coef0 (float) – The independent term in the kernel function. Default is 0.0.
shrinking (bool) – Whether to use the shrinking heuristic. Default is True.
tol (float) – The tolerance for stopping criterion. Default is 0.001.
cache_size (float) – The size of the kernel cache in MB. Default is 200.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the NuSVRRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the NuSVRRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the NuSVRRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.passive_aggressive_regressor module#
- class models.passive_aggressive_regressor.PassiveAggressiveRegressorModel(C=1.0, fit_intercept=True, max_iter=1000, tol=0.001, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, shuffle=True, verbose=0, loss='epsilon_insensitive', epsilon=0.1, random_state=None, warm_start=False, average=False)[source]#
Bases:
models.base.BaseRegressor,sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressorPassiveAggressiveRegressorModel is a regression model based on the Passive Aggressive algorithm.
- Parameters
C (float) – The regularization parameter. Default is 1.0.
fit_intercept (bool) – Whether to calculate the intercept for this model. Default is True.
max_iter (int) – The maximum number of passes over the training data. Default is 1000.
tol (float) – The stopping criterion. Default is 1e-3.
early_stopping (bool) – Whether to use early stopping to terminate training when validation score does not improve. Default is False.
validation_fraction (float) – The proportion of the training data to use as validation set when early stopping is enabled. Default is 0.1.
n_iter_no_change (int) – The maximum number of iterations with no improvement before early stopping. Default is 5.
shuffle (bool) – Whether to shuffle the training data before each epoch. Default is True.
verbose (int) – The verbosity level. Default is 0.
loss (str) – The loss function to use. Can be “epsilon_insensitive” or “squared_epsilon_insensitive”. Default is “epsilon_insensitive”.
epsilon (float) – The epsilon parameter for the epsilon-insensitive loss function. Default is 0.1.
random_state (int, RandomState instance or None) – The seed of the pseudo-random number generator. Default is None.
warm_start (bool) – Whether to reuse the solution of the previous call to fit as initialization. Default is False.
average (bool) – Whether to compute the averaged model. Default is False.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the PassiveAggressiveRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the PassiveAggressiveRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the PassiveAggressiveRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.random_forest_regressor module#
- class models.random_forest_regressor.RandomForestRegressorModel(n_estimators=100, max_depth=None, min_samples_split=2, min_samples_leaf=1, max_features='auto')[source]#
Bases:
models.base.BaseRegressor,sklearn.ensemble._forest.RandomForestRegressorRandomForestRegressorModel is a regression model based on the Random Forest algorithm.
- Parameters
n_estimators (int) – The number of trees in the forest. Default is 100.
max_depth (int or None) – The maximum depth of the tree. None indicates unlimited depth. Default is None.
min_samples_split (int) – The minimum number of samples required to split an internal node. Default is 2.
min_samples_leaf (int) – The minimum number of samples required to be at a leaf node. Default is 1.
max_features (str or int) – The number of features to consider when looking for the best split. ‘auto’ uses sqrt(n_features), ‘sqrt’ uses sqrt(n_features), ‘log2’ uses log2(n_features), None uses n_features, and int specifies the number of features. Default is ‘auto’.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the RandomForestRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the RandomForestRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the RandomForestRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.ridge_regressor module#
- class models.ridge_regressor.RidgeRegressorModel(alpha=1.0)[source]#
Bases:
models.base.BaseRegressor,sklearn.linear_model._ridge.RidgeRidgeRegressorModel is a regression model based on the Ridge regression algorithm.
- Parameters
alpha (float) – The regularization parameter. Default is 1.0.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the RidgeRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the RidgeRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the RidgeRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.support_vector_regressor module#
- class models.support_vector_regressor.SupportVectorRegressorModel(kernel='rbf', degree=3, C=1.0, epsilon=0.1)[source]#
Bases:
models.base.BaseRegressor,sklearn.svm._classes.SVRSupportVectorRegressorModel is a regression model based on the Support Vector Regression algorithm.
- Parameters
kernel (str) – The kernel function to use. Default is “rbf”.
degree (int) – The degree of the polynomial kernel function. Default is 3.
C (float) – The regularization parameter. Default is 1.0.
epsilon (float) – The epsilon-tube parameter in the epsilon-insensitive loss function. Default is 0.1.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the SupportVectorRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the SupportVectorRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the SupportVectorRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.tweedie_regressor module#
- class models.tweedie_regressor.TweedieRegressorModel(power=0, alpha=0.5, link='auto', max_iter=100, tol=0.0001)[source]#
Bases:
models.base.BaseRegressor,sklearn.linear_model._glm.glm.TweedieRegressorTweedieRegressorModel is a regression model based on the Tweedie regression algorithm.
- Parameters
power (float) – The power parameter in the Tweedie variance function. Default is 0.
alpha (float) – The regularization parameter. Default is 0.5.
link (str) – The link function to use. Default is “auto”.
max_iter (int) – The maximum number of iterations. Default is 100.
tol (float) – The tolerance for the optimization algorithm. Default is 0.0001.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the TweedieRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the TweedieRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the TweedieRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple
models.xgb_regressor module#
- class models.xgb_regressor.XGBRegressorModel(n_estimators=100, learning_rate=0.1, max_depth=3, min_child_weight=1, gamma=0, subsample=1, colsample_bytree=1)[source]#
Bases:
models.base.BaseRegressor,xgboost.sklearn.XGBRegressorXGBRegressorModel is a regression model based on the eXtreme Gradient Boosting (XGBoost) algorithm.
- Parameters
n_estimators (int) – The number of boosting iterations. Default is 100.
learning_rate (float) – The learning rate of the boosting process. Default is 0.1.
max_depth (int) – The maximum depth of each tree. Default is 3.
min_child_weight (int) – The minimum sum of instance weight needed in a child. Default is 1.
gamma (float) – The minimum loss reduction required to make a further partition on a leaf node. Default is 0.
subsample (float) – The subsample ratio of the training instances. Default is 1.
colsample_bytree (float) – The subsample ratio of columns when constructing each tree. Default is 1.
- get_params(deep=True)[source]#
Returns the current hyperparameters of the XGBRegressorModel.
- Parameters
deep (bool) – If True, return the parameters of all sub-objects that are estimators. If False, return only the top-level parameters. Default is True.
- Returns
The current hyperparameters of the XGBRegressorModel.
- Return type
dict
- tune_model(X_train, X_val, y_train, y_val)[source]#
Tunes the hyperparameters of the XGBRegressorModel using grid search and cross-validation.
- Parameters
X_train (numpy.ndarray) – The training features.
X_val (numpy.ndarray) – The validation features.
y_train (numpy.ndarray) – The training target.
y_val (numpy.ndarray) – The validation target.
- Returns
A tuple containing the best estimator and the best parameters found during tuning.
- Return type
tuple