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

Uploaded Python 3

File details

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

File metadata

  • Download URL: optimal_regressors-0.6.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.6.0.tar.gz
Algorithm Hash digest
SHA256 42c6c47557ef665b2aa9a51d26b44c3fb915fda6faacc9f019a8429eb875ad6a
MD5 74438b42410a99a06d5250143d40408b
BLAKE2b-256 828257d2a01f27d42dce5001c0118335faea1603c2ae32819e3655dd56a89235

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for optimal_regressors-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 962e779fd640fa35f78a418bbad3a9824c896f452fb2e0ab35c130cd2a72bce8
MD5 486f5c4f3fe7021c85cff0791585ff9f
BLAKE2b-256 0cebd7ecedf3c687d1541aed296d019e684ca8d15f18736ce486b42dcde36e85

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