Skip to content

Instantly share code, notes, and snippets.

@yohanesnuwara
Created August 22, 2021 13:14
Show Gist options
  • Save yohanesnuwara/b6c0dfd90afbe40e8e9a189c60ae4970 to your computer and use it in GitHub Desktop.
Save yohanesnuwara/b6c0dfd90afbe40e8e9a189c60ae4970 to your computer and use it in GitHub Desktop.
Code for optimization 1
# Separate feature and target
X = df.drop(['ROP_AVG'], axis=1)
y = df['ROP_AVG']
# Train test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=10)
# Make pipeline
steps = [('scaler', StandardScaler()),
('gbr', GradientBoostingRegressor(min_samples_leaf=6, max_depth=20,
random_state=10))]
pipe = Pipeline(steps)
# Fit pipeline to training data
pipe.fit(X_train,y_train)
# Evaluate model with R2 metric
train_score = pipe.score(X_train, y_train)
test_score = pipe.score(X_test, y_test)
print(f'R2 on train set: {train_score:.2f}')
print(f'R2 on test set: {test_score:.2f}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment