1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Mon Oct 5 09:50:24 2020
- @author: tanya
- """
- from sklearn.ensemble import RandomForestClassifier
- from sklearn.feature_selection import SelectPercentile
- from sklearn.linear_model import LogisticRegression
- from sklearn.decomposition import PCA
- from sklearn.pipeline import Pipeline
- from sklearn.preprocessing import StandardScaler
- from hyperopt import hp
- import numpy as np
- space = hp.choice("pipelines", [
- {"name": "std_scaler_kbest_rf",
- "pipeline": Pipeline([
- ("std_scaler", StandardScaler()),
- ("kbest", SelectPercentile()),
- ("rf", RandomForestClassifier())]),
- "params": {"kbest__percentile":
- hp.choice('kbest__percentile', range(1, 3)),
- "rf__n_estimators":
- 50 + hp.randint('rf__n_estimators', 50)}},
- {"name": "std_scaler_pca_lr",
- "pipeline": Pipeline([
- ("std_scaler", StandardScaler()),
- ("pca", PCA()),
- ("lr", LogisticRegression())]),
- "params": {"lr__C":
- hp.loguniform("lr__C", np.log(0.01), np.log(0.1)),
- "pca__n_components":
- 1 + hp.randint("pca__n_components", 4)}}
- ])
|