Skip to main content

A Python library to find optimal configurations for regressors and the overall best model.

Project description

Machine Learning Model Optimization

This repository contains a set of utilities designed to automate the process of optimizing machine learning models using various regression and classification algorithms. The code implements hyperparameter tuning for multiple models using RandomizedSearchCV and provides a framework to compare the performance of these models to find the best one for a given dataset.

Features

  • Hyperparameter Optimization: Automatically tunes the hyperparameters of several models (e.g., XGBoost, Decision Trees, Random Forest, KNN, SVM, and more).
  • Model Selection: Compares the performance of different models and returns the best performing regressor or classifier based on validation data.
  • Dataset Classification: Automatically classifies datasets to determine whether they are suited for regression or classification tasks, adjusting the optimization approach accordingly.
  • Cross-validation: Uses cross-validation to ensure robust evaluation during hyperparameter search. Supported Models
  • XGBoost (Regressor and Classifier)
  • Decision Tree Regressor (DTR)
  • Gradient Boosting Regressor (GBR)
  • K-Nearest Neighbors (KNN)
  • Random Forest (RF)
  • Support Vector Machine (SVM)
  • Linear Regression (Ridge,Lasso,Logistic)

Installation

To use the model optimization tools, clone this repository and install the necessary dependencies:

git clone https://github.com/yourusername/ml-model-optimization.git
cd ml-model-optimization
pip install -r requirements.txt

Usage

Importing the Modules

In your project, import the necessary modules:

from OptimalXGB import OptimalXGBoost
from OptimalDTR import OptimalDTR
from OptimalGBR import OptimalGBR
from OptimalKNN import OptimalKNN
from OptimalLinear import OptimalLinear
from OptimalRF import OptimalRF
from OptimalSVM import OptimalSVM
from ClassifyDatasets import classify, get_accuracy_classifiers, get_accuracy_regressors
from regressors import BestModel

Optimizing a Model

To optimize a specific model (e.g., XGBoost Regressor), follow these steps:

  • Prepare your data: Ensure you have the training and validation datasets ready (train_X, train_y, val_X, val_y).
  • Create the optimal model object:
# For regression (XGBoost Regressor example)
optimizer = OptimalXGBoost(train_X, train_y, val_X, val_y, type_='regressor')
  • Run the optimization:
# Perform the optimization
best_model = optimizer.optimize()

# Evaluate the model
train_accuracy, val_accuracy = optimizer.evaluate()

print("Training Accuracy: ", train_accuracy)
print("Validation Accuracy: ", val_accuracy)

This will automatically perform the necessary hyperparameter tuning and return the best regressor or classifier.

Getting Best Model

To get the overall best model by comparing multiple models. follow these steps:

  • Prepare your data: Ensure you have the training and validation datasets ready (train_X, train_y, val_X, val_y).
  • Create the best model object:
# For regression
best_model = BestModel(train_X,train_y,val_X,val_y,type_='regressor')

# Get the best model
best_overall_model = best_model.optimize() # This will directly store the model (like DecisionTreeRegressor(),Ridge()...etc)

#Evaluate Model
training_accuracy,validation_accuracy = best_model.evaluate()

File Structure

ml-model-optimization/
├── __init__.py            # Package initialization
├── ClassifyDatasets.py    # Dataset classification and accuracy calculation
├── OptimalDTR.py          # Decision Tree Regressor optimization
├── OptimalGBR.py          # Gradient Boosting Regressor optimization
├── OptimalKNN.py          # K-Nearest Neighbors optimization
├── OptimalLinear.py       # Linear Regression optimization
├── OptimalRF.py           # Random Forest optimization
├── OptimalSVM.py          # Support Vector Machine optimization
├── OptimalXGB.py          # XGBoost optimization
├── requirements.txt       # Dependencies
├── README.md              # Documentation

Requirements

This project requires the following Python libraries:

  • scikit-learn: For machine learning algorithms and cross-validation.
  • xgboost: For XGBoost regressor and classifier.
  • numpy: For numerical operations.
  • pandas: For data manipulation. You can install the dependencies using pip:
pip install -r requirements.txt

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optimal_regressors-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optimal_regressors-1.0.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file optimal_regressors-1.0.0.tar.gz.

File metadata

  • Download URL: optimal_regressors-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for optimal_regressors-1.0.0.tar.gz
Algorithm Hash digest
SHA256 08919f5e619b71e3ef2061320c257fb70fa81e8fb230ad145232f1f72d5dbf45
MD5 a83f956faa34e542fe30faa3fb5c1978
BLAKE2b-256 51ed6b9fda3b75bb3d9f674e88cc4d3f6696f65045e8990d6a86395305b4347c

See more details on using hashes here.

File details

Details for the file optimal_regressors-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for optimal_regressors-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 564c366d2deffabe66b367352683273edfaa317ba725bc8681b61a4eb7e1756e
MD5 1bb9fd3233a842dad22ec33629ccb57b
BLAKE2b-256 d7330a3ce98152aee7772d00895535d96c09cd8d0b7839933d6018c8c4b53a03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page