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.3.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.3.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: optimal_regressors-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 8afe290be7ab2577b2166587f4ecb8997a87362ac459fa9e668af21a5cce2bac
MD5 10d158ae1ceb19814fca29e8e9859569
BLAKE2b-256 0050018caf25da8fd021c2fedeb69c85ba37ee5f2f7190a462404fc298ba9081

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for optimal_regressors-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2502ba2846b2672dd25bd936a9f7ebbed3e6452f8e678932a5206372894d6eb8
MD5 ba36bfeabe80b81fa632441b582add50
BLAKE2b-256 6b17e503f93d3b7d87effcf0a6aee18758d2274f05a9a3a330930023e1bd370a

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