Path: blob/main/Lessons/Lesson 08 - Hyperparameter Optimization (Project)/tpot_XGBregressor.py
871 views
import numpy as np1import pandas as pd2from sklearn.model_selection import train_test_split3from xgboost import XGBRegressor45# NOTE: Make sure that the outcome column is labeled 'target' in the data file6tpot_data = pd.read_csv('PATH/TO/DATA/FILE', sep='COLUMN_SEPARATOR', dtype=np.float64)7features = tpot_data.drop('target', axis=1)8training_features, testing_features, training_target, testing_target = \9train_test_split(features, tpot_data['target'], random_state=8675309)1011# Average CV score on the training set was: 0.974423805872599212exported_pipeline = XGBRegressor(learning_rate=0.1, max_depth=7, min_child_weight=1, n_estimators=100, objective="reg:squarederror", reg_alpha=2.75, reg_lambda=2.5, subsample=0.6500000000000001)13# Fix random state in exported estimator14if hasattr(exported_pipeline, 'random_state'):15setattr(exported_pipeline, 'random_state', 8675309)1617exported_pipeline.fit(training_features, training_target)18results = exported_pipeline.predict(testing_features)192021