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

Uploaded Python 3

File details

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

File metadata

  • Download URL: optimal_regressors-0.5.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.5.0.tar.gz
Algorithm Hash digest
SHA256 1c0783af8e371265e753170bc7c31a999ad76d64d1b15bc28d175e58308969d0
MD5 b8fdd82c3b85b2568075c491501e23b9
BLAKE2b-256 a18300e409b86674b364018a78f41f5756297644db022893f19f5817ecdf6b5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for optimal_regressors-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bcc7a910144bba0742085fa684c4e0fb82363a32c173b1bdac88e83ea412b6b1
MD5 f4b4f8bda34b69ba3ef218242d90e2dc
BLAKE2b-256 ea4a91a00964a1c17072f241caa99f1ef3ce5f4e9cba8c8bfbf04bc6e6ba4d51

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