### Install hyperopt-sklearn via pip Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md Instructions for installing the hyperopt-sklearn library using pip, including options for installing the latest stable version or specific tags, branches, or commits directly from the GitHub repository. ```bash pip install hyperopt-sklearn ``` ```bash pip install git+https://github.com/hyperopt/hyperopt-sklearn@1.0.3 ``` ```bash pip install git+https://github.com/hyperopt/hyperopt-sklearn@master ``` ```bash pip install git+https://github.com/hyperopt/hyperopt-sklearn@fd718c44fc440bd6e2718ec1442b1af58cafcb18 ``` -------------------------------- ### Complete hyperparameter optimization example with Iris dataset Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md A comprehensive example demonstrating hyperparameter optimization using hyperopt-sklearn on the Iris dataset. It includes data loading, splitting into training and test sets, `HyperoptEstimator` instantiation with `any_classifier` and `any_preprocessing`, and evaluation of the best model found. ```python from hpsklearn import HyperoptEstimator, any_classifier, any_preprocessing from sklearn.datasets import load_iris from hyperopt import tpe import numpy as np # Download the data and split into training and test sets iris = load_iris() X = iris.data y = iris.target test_size = int(0.2 * len(y)) np.random.seed(13) indices = np.random.permutation(len(X)) X_train = X[indices[:-test_size]] y_train = y[indices[:-test_size]] X_test = X[indices[-test_size:]] y_test = y[indices[-test_size:]] if __name__ == "__main__": # Instantiate a HyperoptEstimator with the search space and number of evaluations estim = HyperoptEstimator(classifier=any_classifier("my_clf"), preprocessing=any_preprocessing("my_pre"), algo=tpe.suggest, max_evals=100, trial_timeout=120) # Search the hyperparameter space based on the data estim.fit(X_train, y_train) # Show the results print(estim.score(X_test, y_test)) # 1.0 print(estim.best_model()) # {'learner': ExtraTreesClassifier(bootstrap=False, class_weight=None, criterion='gini', # max_depth=3, max_features='log2', max_leaf_nodes=None, # min_impurity_decrease=0.0, min_impurity_split=None, # min_samples_leaf=1, min_samples_split=2, # min_weight_fraction_leaf=0.0, n_estimators=13, n_jobs=1, # oob_score=False, random_state=1, verbose=False, # warm_start=False), 'preprocs': (), 'ex_preprocs': ()} ``` -------------------------------- ### Partial MNIST example with specific classifier Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md An incomplete code snippet demonstrating the initial setup for a hyperparameter optimization task on the MNIST dataset, specifically importing `extra_tree_classifier` for use with `HyperoptEstimator`. ```python from hpsklearn import HyperoptEstimator, extra_tree_classifier from sklearn.datasets import load_digits from hyperopt import tpe import numpy as np ``` -------------------------------- ### Optimize Hyperparameters with HyperoptEstimator Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md This example demonstrates how to instantiate and use `HyperoptEstimator` from `hyperopt-sklearn` to perform hyperparameter optimization. It configures an Extra Trees Classifier, sets the TPE algorithm for search, and evaluates the best model's performance on a test set. ```python if __name__ == "__main__": # Instantiate a HyperoptEstimator with the search space and number of evaluations estim = HyperoptEstimator(classifier=extra_tree_classifier("my_clf"), preprocessing=[], algo=tpe.suggest, max_evals=10, trial_timeout=300) # Search the hyperparameter space based on the data estim.fit(X_train, y_train) # Show the results print(estim.score(X_test, y_test)) # 0.962785714286 print(estim.best_model()) # {'learner': ExtraTreesClassifier(bootstrap=True, class_weight=None, criterion='entropy', # max_depth=None, max_features=0.959202875857, # max_leaf_nodes=None, min_impurity_decrease=0.0, # min_impurity_split=None, min_samples_leaf=1, # min_samples_split=2, min_weight_fraction_leaf=0.0, # n_estimators=20, n_jobs=1, oob_score=False, random_state=3, # verbose=False, warm_start=False), 'preprocs': (), 'ex_preprocs': ()} ``` -------------------------------- ### Python Project Dependencies Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/requirements.txt Specifies the exact Python libraries and their version constraints required for the hyperopt-sklearn project. This ensures environment reproducibility and compatibility across different development setups. ```Python hyperopt==0.2.7 numpy>=2.0.0,<=2.3.0 scikit-learn>=1.5,<=1.7 scipy>=1.15.0,<=1.15.3 pandas>=2.1.0,<=2.3.0 setuptools>=71.0.0 ``` -------------------------------- ### HyperoptEstimator Preprocessing Parameter and Generic Search Spaces Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md Explains how to configure preprocessing steps within `HyperoptEstimator` using specific functions for generic search spaces or individual modules. It details the expected list format for the `preprocessing` parameter and provides guidance on handling different data types like sparse matrices or raw text. ```APIDOC HyperoptEstimator: __init__(self, ..., preprocessing: list = None, ...) preprocessing: list A list of preprocessing steps to be chained. Each element in the list represents a preprocessing transformation. Usage Notes: - The `preprocessing` parameter expects a list. - To skip preprocessing, pass an empty list: `[]`. Generic Search Space Functions: - `any_preprocessing()`: Returns a generic search space for various preprocessing algorithms. Returns: list (already returns a list, no wrapping needed) - `any_sparse_preprocessing()`: Returns a search space suitable for sparse matrix data. Returns: list (already returns a list, no wrapping needed) - `all_preprocessing()`: Returns a complete search space across all available preprocessing algorithms. Returns: object (does NOT return a list; must be wrapped in a list, e.g., `[all_preprocessing()]`) - `any_text_preprocessing()`: Returns a search space for raw text data preprocessing. Currently uses TFIDF. Returns: list (already returns a list, no wrapping needed) Example: `HyperoptEstimator(preprocessing=[standard_scaler, pca])` `HyperoptEstimator(preprocessing=any_preprocessing())` ``` -------------------------------- ### Load and Split Digits Dataset for Hyperopt-Sklearn Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md This snippet loads the scikit-learn digits dataset, shuffles it, and splits it into training and testing sets. This prepared data is then used for hyperparameter optimization tasks with hyperopt-sklearn. ```python digits = load_digits() X = digits.data y = digits.target test_size = int(0.2 * len(y)) np.random.seed(13) indices = np.random.permutation(len(X)) X_train = X[indices[:-test_size]] y_train = y[indices[:-test_size]] X_test = X[indices[-test_size:]] y_test = y[indices[-test_size:]] ``` -------------------------------- ### Basic HyperoptEstimator usage with scikit-learn SVC Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md Demonstrates how to integrate hyperopt-sklearn with a standard scikit-learn pipeline. It shows a one-line change to replace a standard estimator (e.g., svm.SVC) with a HyperoptEstimator for automatic hyperparameter search, then fits and scores the model. ```python from hpsklearn import HyperoptEstimator, svc from sklearn import svm # Load Data # ... if __name__ == "__main__": if use_hpsklearn: estim = HyperoptEstimator(classifier=svc("mySVC")) else: estim = svm.SVC() estim.fit(X_train, y_train) print(estim.score(X_test, y_test)) # <> ``` -------------------------------- ### Hyperopt-Sklearn Available Regressors Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md A comprehensive list of regressor components available for hyperparameter optimization within `hyperopt-sklearn`. These components can be used with `HyperoptEstimator` to define search spaces for regression tasks. ```APIDOC random_forest_regressor extra_trees_regressor bagging_regressor isolation_forest ada_boost_regressor gradient_boosting_regressor hist_gradient_boosting_regressor linear_regression bayesian_ridge ard_regression lars lasso_lars lars_cv lasso_lars_cv lasso_lars_ic lasso elastic_net lasso_cv elastic_net_cv multi_task_lasso multi_task_elastic_net multi_task_lasso_cv multi_task_elastic_net_cv poisson_regressor gamma_regressor tweedie_regressor huber_regressor sgd_regressor ridge ridge_cv logistic_regression logistic_regression_cv orthogonal_matching_pursuit orthogonal_matching_pursuit_cv passive_aggressive_regressor quantile_regression ransac_regression theil_sen_regressor dummy_regressor gaussian_process_regressor mlp_regressor cca pls_canonical pls_regression linear_svr nu_svr one_class_svm svr decision_tree_regressor extra_tree_regressor transformed_target_regressor hp_sklearn_kernel_ridge bayesian_gaussian_mixture gaussian_mixture k_neighbors_regressor radius_neighbors_regressor k_means mini_batch_k_means xgboost_regression lightgbm_regression ``` -------------------------------- ### Hyperopt-Sklearn Available Classifiers Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md A comprehensive list of classifier components available for hyperparameter optimization within `hyperopt-sklearn`. These components can be used with `HyperoptEstimator` to define search spaces for classification tasks. ```APIDOC random_forest_classifier extra_trees_classifier bagging_classifier ada_boost_classifier gradient_boosting_classifier hist_gradient_boosting_classifier bernoulli_nb categorical_nb complement_nb gaussian_nb multinomial_nb sgd_classifier sgd_one_class_svm ridge_classifier ridge_classifier_cv passive_aggressive_classifier perceptron dummy_classifier gaussian_process_classifier mlp_classifier linear_svc nu_svc svc decision_tree_classifier extra_tree_classifier label_propagation label_spreading elliptic_envelope linear_discriminant_analysis quadratic_discriminant_analysis bayesian_gaussian_mixture gaussian_mixture k_neighbors_classifier radius_neighbors_classifier nearest_centroid xgboost_classification lightgbm_classification one_vs_rest one_vs_one output_code ``` -------------------------------- ### Available Preprocessing Modules in Hyperopt-Sklearn Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md A comprehensive list of preprocessing modules and transformers supported by hyperopt-sklearn, categorized by their primary function (e.g., scaling, encoding, vectorization, dimensionality reduction). These names correspond to callable objects or functions that can be used in the preprocessing pipeline. ```Python binarizer min_max_scaler max_abs_scaler normalizer robust_scaler standard_scaler quantile_transformer power_transformer one_hot_encoder ordinal_encoder polynomial_features spline_transformer k_bins_discretizer tfidf_vectorizer hashing_vectorizer count_vectorizer pca ts_lagselector colkmeans ``` -------------------------------- ### Define Python Package Dependencies Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/requirements_dev.txt Specifies the required Python packages and their exact or minimum/maximum version constraints for the project. This ensures environment consistency and reproducibility across different development and deployment environments. It also includes a reference to another requirements file for additional dependencies. ```Python tox>=4.20.0 xgboost>=2.0.0,<=2.2.0 lightgbm==4.6.0 coverage==7.6.12 -r requirements.txt ``` -------------------------------- ### Customize hyperparameter search space for SGDClassifier Source: https://github.com/hyperopt/hyperopt-sklearn/blob/master/README.md Illustrates how to define custom search spaces for hyperparameters using `hyperopt.hp` functions. It shows how to fix a parameter value (e.g., 'penalty' to 'l2') and define probabilistic choices ('loss') or log-uniform distributions ('alpha') for others within the HyperoptEstimator. ```python from hpsklearn import HyperoptEstimator, sgd_classifier from hyperopt import hp import numpy as np sgd_penalty = "l2" sgd_loss = hp.pchoice("loss", [(0.50, "hinge"), (0.25, "log"), (0.25, "huber")]) sgd_alpha = hp.loguniform("alpha", low=np.log(1e-5), high=np.log(1)) if __name__ == "__main__": estim = HyperoptEstimator(classifier=sgd_classifier("my_sgd", penalty=sgd_penalty, loss=sgd_loss, alpha=sgd_alpha)) estim.fit(X_train, y_train) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.