sk-stepwise-1


Namesk-stepwise-1 JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryStepwise selection for scikit-learn models
upload_time2024-10-20 09:02:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sk-stepwise

## Overview

`StepwiseHyperoptOptimizer` is a custom Python class that combines the power of the Hyperopt optimization library with a stepwise optimization strategy for hyperparameter tuning of machine learning models. It extends the capabilities of scikit-learn's `BaseEstimator` and `MetaEstimatorMixin`, making it easy to integrate into existing machine learning workflows.

This class enables you to optimize a model's hyperparameters in a sequential manner, following a predefined series of hyperparameter spaces. Each step in the sequence focuses on refining a specific set of parameters, allowing for a more targeted and efficient optimization process. The hyperparameter optimization uses Tree of Parzen Estimators (TPE) through the Hyperopt library.

## Features

- **Stepwise Hyperparameter Tuning**: Break down the optimization process into multiple steps, each refining a specific set of hyperparameters.
- **Hyperopt Integration**: Utilize Hyperopt's TPE algorithm to find the optimal parameters efficiently.
- **Scikit-learn Compatibility**: `StepwiseHyperoptOptimizer` is compatible with the scikit-learn ecosystem, making it easy to use in scikit-learn pipelines and workflows.
- **Flexible Scoring**: Supports both default scikit-learn scoring metrics and custom scoring functions.

## Installation

```sh
pip install sk-stepwise
```

## Usage

Here's an example of how to use `StepwiseHyperoptOptimizer` to optimize a scikit-learn model:

```python
>>> import numpy as np
>>> import pandas as pd
>>> from sklearn.ensemble import RandomForestRegressor
>>> from sk_stepwise import StepwiseHyperoptOptimizer
>>> import hyperopt

>>> # Sample data
>>> X = pd.DataFrame(np.random.rand(100, 5), columns=[f"feature_{i}" for i in range(5)])
>>> y = pd.Series(np.random.rand(100))

>>> # Define the model
>>> model = RandomForestRegressor()

>>> # Define the parameter space sequence for stepwise optimization
>>> param_space_sequence = [
...     {"n_estimators": hyperopt.hp.choice("n_estimators", [50, 100, 150])},
...     {"max_depth": hyperopt.hp.quniform("max_depth", 3, 10, 1)},
...     {"min_samples_split": hyperopt.hp.uniform("min_samples_split", 0.1, 1.0)},
... ]

>>> # Create the optimizer
>>> optimizer = StepwiseHyperoptOptimizer(model=model, param_space_sequence=param_space_sequence, max_evals_per_step=50)

>>> # Fit the optimizer
>>> optimizer.fit(X, y)

>>> # Make predictions
>>> predictions = optimizer.predict(X)
```

## Key Methods

- `fit(X, y)`: Fits the optimizer to the data, performing stepwise hyperparameter optimization.
- `predict(X)`: Uses the optimized model to make predictions.
- `score(X, y)`: Evaluates the optimized model on a test set.

## Parameters

- **model** (`_Fitable`): A scikit-learn compatible model that implements `fit`, `predict`, and `set_params` methods.
- **param_space_sequence** (`list[dict]`): A list of dictionaries representing the hyperparameter spaces for each optimization step.
- **max_evals_per_step** (`int`): The maximum number of evaluations to perform for each step of the optimization.
- **cv** (`int`): Number of cross-validation folds.
- **scoring** (`str` or `Callable`): The scoring metric to use for evaluation. Default is "neg_mean_squared_error".
- **random_state** (`int`): Random seed for reproducibility.

## Contributing

Contributions are welcome! Feel free to open issues or pull requests for new features, bug fixes, or documentation improvements.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgements

- [Hyperopt](https://github.com/hyperopt/hyperopt) for hyperparameter optimization.
- [scikit-learn](https://scikit-learn.org) for model implementation and evaluation utilities.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sk-stepwise-1",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/34/6a/9e6e9cd76757f8d55d675c42f59b79baf6014ecce208c801fe58c541983b/sk_stepwise_1-0.1.1.tar.gz",
    "platform": null,
    "description": "# sk-stepwise\n\n## Overview\n\n`StepwiseHyperoptOptimizer` is a custom Python class that combines the power of the Hyperopt optimization library with a stepwise optimization strategy for hyperparameter tuning of machine learning models. It extends the capabilities of scikit-learn's `BaseEstimator` and `MetaEstimatorMixin`, making it easy to integrate into existing machine learning workflows.\n\nThis class enables you to optimize a model's hyperparameters in a sequential manner, following a predefined series of hyperparameter spaces. Each step in the sequence focuses on refining a specific set of parameters, allowing for a more targeted and efficient optimization process. The hyperparameter optimization uses Tree of Parzen Estimators (TPE) through the Hyperopt library.\n\n## Features\n\n- **Stepwise Hyperparameter Tuning**: Break down the optimization process into multiple steps, each refining a specific set of hyperparameters.\n- **Hyperopt Integration**: Utilize Hyperopt's TPE algorithm to find the optimal parameters efficiently.\n- **Scikit-learn Compatibility**: `StepwiseHyperoptOptimizer` is compatible with the scikit-learn ecosystem, making it easy to use in scikit-learn pipelines and workflows.\n- **Flexible Scoring**: Supports both default scikit-learn scoring metrics and custom scoring functions.\n\n## Installation\n\n```sh\npip install sk-stepwise\n```\n\n## Usage\n\nHere's an example of how to use `StepwiseHyperoptOptimizer` to optimize a scikit-learn model:\n\n```python\n>>> import numpy as np\n>>> import pandas as pd\n>>> from sklearn.ensemble import RandomForestRegressor\n>>> from sk_stepwise import StepwiseHyperoptOptimizer\n>>> import hyperopt\n\n>>> # Sample data\n>>> X = pd.DataFrame(np.random.rand(100, 5), columns=[f\"feature_{i}\" for i in range(5)])\n>>> y = pd.Series(np.random.rand(100))\n\n>>> # Define the model\n>>> model = RandomForestRegressor()\n\n>>> # Define the parameter space sequence for stepwise optimization\n>>> param_space_sequence = [\n...     {\"n_estimators\": hyperopt.hp.choice(\"n_estimators\", [50, 100, 150])},\n...     {\"max_depth\": hyperopt.hp.quniform(\"max_depth\", 3, 10, 1)},\n...     {\"min_samples_split\": hyperopt.hp.uniform(\"min_samples_split\", 0.1, 1.0)},\n... ]\n\n>>> # Create the optimizer\n>>> optimizer = StepwiseHyperoptOptimizer(model=model, param_space_sequence=param_space_sequence, max_evals_per_step=50)\n\n>>> # Fit the optimizer\n>>> optimizer.fit(X, y)\n\n>>> # Make predictions\n>>> predictions = optimizer.predict(X)\n```\n\n## Key Methods\n\n- `fit(X, y)`: Fits the optimizer to the data, performing stepwise hyperparameter optimization.\n- `predict(X)`: Uses the optimized model to make predictions.\n- `score(X, y)`: Evaluates the optimized model on a test set.\n\n## Parameters\n\n- **model** (`_Fitable`): A scikit-learn compatible model that implements `fit`, `predict`, and `set_params` methods.\n- **param_space_sequence** (`list[dict]`): A list of dictionaries representing the hyperparameter spaces for each optimization step.\n- **max_evals_per_step** (`int`): The maximum number of evaluations to perform for each step of the optimization.\n- **cv** (`int`): Number of cross-validation folds.\n- **scoring** (`str` or `Callable`): The scoring metric to use for evaluation. Default is \"neg_mean_squared_error\".\n- **random_state** (`int`): Random seed for reproducibility.\n\n## Contributing\n\nContributions are welcome! Feel free to open issues or pull requests for new features, bug fixes, or documentation improvements.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgements\n\n- [Hyperopt](https://github.com/hyperopt/hyperopt) for hyperparameter optimization.\n- [scikit-learn](https://scikit-learn.org) for model implementation and evaluation utilities.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Stepwise selection for scikit-learn models",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7080bb3287312dbaa6dd5e77093f6993a092a04f1c653d6893b2752d060eca0d",
                "md5": "7076d11923925c54ae05f9d462bc72f2",
                "sha256": "b83a45b982b3023caed1dc65d79f1b29e0dbc260ad3e73d64486dccd88659929"
            },
            "downloads": -1,
            "filename": "sk_stepwise_1-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7076d11923925c54ae05f9d462bc72f2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 4266,
            "upload_time": "2024-10-20T09:02:04",
            "upload_time_iso_8601": "2024-10-20T09:02:04.280642Z",
            "url": "https://files.pythonhosted.org/packages/70/80/bb3287312dbaa6dd5e77093f6993a092a04f1c653d6893b2752d060eca0d/sk_stepwise_1-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "346a9e6e9cd76757f8d55d675c42f59b79baf6014ecce208c801fe58c541983b",
                "md5": "34abe1287010485cd68b59a25c53cc0f",
                "sha256": "044ba8127f9cac6b4f3932555b94aa9124e5a97ca08d545e5999cfbf31ee0d7e"
            },
            "downloads": -1,
            "filename": "sk_stepwise_1-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "34abe1287010485cd68b59a25c53cc0f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 4477,
            "upload_time": "2024-10-20T09:02:05",
            "upload_time_iso_8601": "2024-10-20T09:02:05.897427Z",
            "url": "https://files.pythonhosted.org/packages/34/6a/9e6e9cd76757f8d55d675c42f59b79baf6014ecce208c801fe58c541983b/sk_stepwise_1-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-20 09:02:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sk-stepwise-1"
}
        
Elapsed time: 0.83032s