Feb-08-2023, 06:34 PM
(This post was last modified: Feb-08-2023, 06:34 PM by Led_Zeppelin.)
In the following code I need to know exactly what the two lines of code are doing:
#!/usr/bin/env python
# coding: utf-8
# In[1]:
Any help appreciated.
Respectfully,
Led_Zeppelin
I have now added three sections. I is a screenshot of the whole program and its output. I thought it might be helpful in answering my question.
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import numpy as np import pandas as pd # In[2]: data = pd.read_csv("concrete_data.csv") data.head() # In[3]: X = data.iloc[:, :8].values Y = data.iloc[:, 8].values.reshape(-1,1) # In[4]: print(np.shape(X)) print(np.shape(Y)) # In[5]: from sklearn.model_selection import train_test_split X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = .2, random_state=2021) # In[6]: from xgboost import XGBRegressor xgb_model = XGBRegressor(random_state = 2021) # In[7]: # make a dictionary of hyperparameter values to search search_space = { "n_estimators" : [100, 200, 500], "max_depth" : [3, 6, 9], "gamma" : [0.01, 0.1], "learning_rate" : [0.001, 0.01, 0.1, 1] } # In[8]: from sklearn.model_selection import GridSearchCV # make a GridSearchCV object GS = GridSearchCV(estimator = xgb_model, param_grid = search_space, scoring = ["r2", "neg_root_mean_squared_error"], #sklearn.metrics.SCORERS.keys() refit = "r2", cv = 5, verbose = 1) # In[9]: GS.fit(X_train, Y_train) # In[10]: print(GS.best_estimator_) # to get the complete details of the best model # In[11]: print(GS.best_params_) # to get only the best hyperparameter values that we searched for # In[12]: print(GS.best_score_) # score according to the metric we passed in refit # In[13]: df = pd.DataFrame(GS.cv_results_) df = df.sort_values("rank_test_r2") df.to_csv("cv_results.csv", index = False)In lines 15 and 16, I know that they are selecting columns. I just do not know what columns they are selecting.
Any help appreciated.
Respectfully,
Led_Zeppelin
I have now added three sections. I is a screenshot of the whole program and its output. I thought it might be helpful in answering my question.