Skip to content

Instantly share code, notes, and snippets.

@Wann-Jiun
Created January 20, 2017 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wann-Jiun/77498ab48990883a22812cd0c1ab7036 to your computer and use it in GitHub Desktop.
Save Wann-Jiun/77498ab48990883a22812cd0c1ab7036 to your computer and use it in GitHub Desktop.
# Kernel Ridge GridSearch
from sklearn.kernel_ridge import KernelRidge
kridge_grid = KernelRidge()
parameter_grid = {'alpha': [0.0001,0.001,0.01,0.1],
'degree': [1,2,3,4],
'kernel': ['polynomial']
#'n_estimators': [200,210,240,250],
#'min_child_weight': [1,2,3,4]
}
cross_validation = StratifiedKFold(np.array(label_df['SalePrice']), n_folds=10)
grid_search_kridge = GridSearchCV(kridge_grid,
param_grid = parameter_grid,
scoring = 'mean_squared_error',
cv = cross_validation)
grid_search_kridge.fit(train_df_munged, label_df)
print('Best score (Kernel Ridge): {}'.format(grid_search_kridge.best_score_))
print('Best parameters: {}'.format(grid_search_kridge.best_params_))
y_train_pred_kridge = grid_search_kridge.best_estimator_.predict(train_df_munged)
print("Kernel Ridge score on training set: ", rmse(label_df,y_train_pred_kridge))
y_test_pred_kridge = grid_search_kridge.best_estimator_.predict(test_df_munged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment