Skip to content

Instantly share code, notes, and snippets.

Created May 18, 2020 06:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Alakhator/855072e0ca8e585f5b2eab631cd6848a to your computer and use it in GitHub Desktop.
dtr = DecisionTreeRegressor(),Y_train)
y_pred = dtr.predict(X_test)
submission['Purchase'] = y_pred_dt
mse = mean_squared_error(Y_test, y_pred)
print("RMSE Error:", np.sqrt(mse))
r2 = r2_score(Y_test, y_pred)
print("R2 Score:", r2)
feature_important = dtr.get_score(importance_type='gain')
keys = list(feature_important.keys())
values = list(feature_important.values())
total = sum(values)
new = [value * 100. / total for value in values]
new = np.round(new,2)
feature_importances = pd.DataFrame()
feature_importances['Features'] = keys
feature_importances['Importance (%)'] = new
feature_importances = feature_importances.sort_values(['Importance (%)'],ascending=False).reset_index(drop=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment