Created
May 18, 2020 06:34
-
-
Save Alakhator/855072e0ca8e585f5b2eab631cd6848a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dtr = DecisionTreeRegressor() | |
dtr.fit(X_train,Y_train) | |
y_pred = dtr.predict(X_test) | |
y_pred_dt=dtr.predict(test) | |
submission['Purchase'] = y_pred_dt | |
submission.to_csv('dtr_model3.csv',index=False) | |
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) | |
feature_importances | |
feature_importances.style.set_properties(**{'font-size':'10pt'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment