Path: blob/main/Lessons/Lesson 08 - Hyperparameter Optimization (Project)/tpot_optimal_pipeline.py
871 views
import numpy as np1import pandas as pd2from sklearn.ensemble import ExtraTreesRegressor3from sklearn.linear_model import RidgeCV4from sklearn.model_selection import train_test_split5from sklearn.pipeline import make_pipeline, make_union6from tpot.builtins import StackingEstimator7from tpot.export_utils import set_param_recursive89# NOTE: Make sure that the outcome column is labeled 'target' in the data file10tpot_data = pd.read_csv('PATH/TO/DATA/FILE', sep='COLUMN_SEPARATOR', dtype=np.float64)11features = tpot_data.drop('target', axis=1)12training_features, testing_features, training_target, testing_target = \13train_test_split(features, tpot_data['target'], random_state=8675309)1415# Average CV score on the training set was: 0.973385535298740116exported_pipeline = make_pipeline(17StackingEstimator(estimator=RidgeCV()),18ExtraTreesRegressor(bootstrap=True, max_features=0.6500000000000001, min_samples_leaf=1, min_samples_split=3, n_estimators=100)19)20# Fix random state for all the steps in exported pipeline21set_param_recursive(exported_pipeline.steps, 'random_state', 8675309)2223exported_pipeline.fit(training_features, training_target)24results = exported_pipeline.predict(testing_features)252627