Skip to content

Instantly share code, notes, and snippets.

@yashprakash13
Created January 5, 2022 16:49
Show Gist options
  • Save yashprakash13/d6c38cc2950176ee5c7c21a57c2af164 to your computer and use it in GitHub Desktop.
Save yashprakash13/d6c38cc2950176ee5c7c21a57c2af164 to your computer and use it in GitHub Desktop.
from sklearn.model_selection import train_test_split
X = df.drop(columns=['median_house_value'])
y = df.median_house_value
# split the data
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=0)
X_train.shape, X_val.shape, y_train.shape, y_val.shape
# make a new regressor model
regressor = xgb.XGBRegressor(objective ='reg:squarederror',
colsample_bytree = 1,
eta=0.3,
learning_rate = 0.01,
max_depth = 5,
alpha = 10,
n_estimators = 500)
# fit on training set
regressor.fit(X_train, y_train)
# predict on validation set
y_pred = regressor.predict(X_val)
# calculate RMSE
from sklearn.metrics import mean_squared_error
root_mean_squared_error = mean_squared_error(y_val, y_pred, squared=False)
root_mean_squared_error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment