Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. from itertools import product
  2.  
  3. X_Reduced, X_Test_Reduced, Y_Reduced, Y_Test_Reduced = train_test_split(X_pca, Y,
  4. test_size = 0.30,
  5. random_state = 101)
  6. trainedforest = RandomForestClassifier(n_estimators=700).fit(X_Reduced,Y_Reduced)
  7.  
  8. x_min, x_max = X_Reduced[:, 0].min() - 1, X_Reduced[:, 0].max() + 1
  9. y_min, y_max = X_Reduced[:, 1].min() - 1, X_Reduced[:, 1].max() + 1
  10. xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.1), np.arange(y_min, y_max, 0.1))
  11. Z = trainedforest.predict(np.c_[xx.ravel(), yy.ravel()])
  12. Z = Z.reshape(xx.shape)
  13. plt.contourf(xx, yy, Z,cmap=plt.cm.coolwarm, alpha=0.4)
  14. plt.scatter(X_Reduced[:, 0], X_Reduced[:, 1], c=Y_Reduced, s=20, edgecolor='k')
  15. plt.xlabel('Principal Component 1', fontsize = 12)
  16. plt.ylabel('Principal Component 2', fontsize = 12)
  17. plt.title('Random Forest', fontsize = 15)
  18. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement