Python Forum
What are these python lines for? What are tey doing?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What are these python lines for? What are tey doing?
#1
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]:

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.

Attached Files

Thumbnail(s)
           
Reply


Messages In This Thread
What are these python lines for? What are tey doing? - by Led_Zeppelin - Feb-08-2023, 06:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python seems to be skipping lines of code alansandbucket 1 4,217 Jun-22-2021, 01:18 AM
Last Post: Larz60+
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 6,032 Aug-10-2020, 11:01 PM
Last Post: medatib531
  How to re run lines in python? MrDoggo124 5 4,624 May-19-2019, 06:29 PM
Last Post: MrDoggo124
  Arrange lines in python pythonlover 11 7,362 Sep-15-2017, 11:34 PM
Last Post: pythonlover
  parallel(offset) lines using python johnfriend 1 4,319 May-05-2017, 06:10 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020