Skip to main content

A Python library to find optimal configurations for regressors

Project description

OptimalRegressors

OptimalRegressors is a Python library designed to find the optimal configurations for decision tree and random forest regressors. It automates hyperparameter tuning, such as determining the optimal number of leaf nodes, using validation data to improve model performance.

Features

  • Automatically optimizes hyperparameters for:
    • DecisionTreeRegressor
    • RandomForestRegressor
  • Allows custom candidate values for hyperparameter tuning.
  • Optionally fits the optimized model for direct use.
  • Simple, lightweight, and easy to use.

Installation

To install OptimalRegressors, follow the steps below:

Clone the Repository

git clone https://github.com/RehanTaneja/OptimalRegressors.git
cd OptimalRegressors

Install Dependencies

Use pip to install the required dependencies:

pip install -r requirements.txt

Usage

Optimal Decision Tree Regressor

  • Parameters:
    • trainX,trainy Training data (features & labels)
    • valX,valy Validation data (features & labels)
    • candidate_nodes (list, optional): A list of max_leaf_nodes values to test. Default: [5, 50, 500, 5000]
    • fit (bool, optional): Whether to fit the returned model on the training data. Default: False
  • Returns:
    • model: A DecisionTreeRegressor instance with the optimal configuration
    • nodes: The optimal max_leaf_nodes value

Find the best max_leaf_nodes for a decision tree:

from OptimalRegressor import OptimalDecisionTreeRegressor

# Example data (replace with your dataset)
trainX, trainy = [[1], [2], [3]], [2.5, 3.5, 5.0]
valX, valy = [[1.5], [2.5]], [3.0, 4.0]

# Get the optimal DecisionTreeRegressor
model, nodes = OptimalDecisionTreeRegressor(trainX, trainy, valX, valy)

print("Optimal max_leaf_nodes:", nodes)

Optimal Random Forest Regressor

  • Parameters:
    • trainX, trainy: Training data (features and labels)
    • trainX, trainy: Training data (features and labels)
    • candidate_nodes (list, optional): A list of max_leaf_nodes values to test. Default: [5, 50, 500, 5000]
    • fit (bool, optional): Whether to fit the returned model on the training data. Default: False
  • Returns:
    • model: A RandomForestRegressor instance with the optimal configuration
    • nodes: The optimal max_leaf_nodes value

Find the best max_leaf_nodes value for a random forest regressor

from OptimalRegressor import OptimalRandomForestRegressor

# Example data (replace with your dataset)
trainX, trainy = [[1], [2], [3]], [2.5, 3.5, 5.0]
valX, valy = [[1.5], [2.5]], [3.0, 4.0]

# Get the optimal RandomForestRegressor
model, nodes = OptimalRandomForestRegressor(trainX, trainy, valX, valy)

print("Optimal max_leaf_nodes:", nodes)

Repository Structure

OptimalRegressors/ │ ├── OptimalRegressor.py # Main library file ├── requirements.txt # Python dependencies ├── LICENSE # License information └── README.md # Project documentation

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-0.4.0.tar.gz (2.6 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-0.4.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for optimal_regressors-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a49c7486ef8546169e70e4ec532e55cb11b35e9d27524014ee019df04635aaf0
MD5 7ee69bf8f8962d1ae5c723b5667399d4
BLAKE2b-256 a909f0f1acdfc763b4e8727372bca558a8ec823d889d857d2b26cf7c68353ae3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for optimal_regressors-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 decdbe061210c1fe5c3c25902e0204de32b2cfa1cf6c0e35261e0c7765c9910d
MD5 b40c2b1f78a20e7533288f6f3b3eacb8
BLAKE2b-256 ffdd91b69e48397863f59a3e8a1a9f136ce1aab8d75e39f6bb40394e3661f7db

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