random forest classifier predict probability code example

Example 1: polynomial features random forest classifier

pd.read_csv()

Example 2: how to improve accuracy of random forest classifier

# List of features sorted from most to least importantsorted_importances = [importance[1] for importance in feature_importances]sorted_features = [importance[0] for importance in feature_importances]# Cumulative importancescumulative_importances = np.cumsum(sorted_importances)# Make a line graphplt.plot(x_values, cumulative_importances, 'g-')# Draw line at 95% of importance retainedplt.hlines(y = 0.95, xmin=0, xmax=len(sorted_importances), color = 'r', linestyles = 'dashed')# Format x ticks and labelsplt.xticks(x_values, sorted_features, rotation = 'vertical')# Axis labels and titleplt.xlabel('Variable'); plt.ylabel('Cumulative Importance'); plt.title('Cumulative Importances');