Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. from sklearn.ensemble import RandomForestClassifier
  2.  
  3. # Initialize a classifier object with default params
  4. classifier = RandomForestClassifier()
  5. classifier.fit(X_train, y_train)
  6.  
  7. # Make predictions using both train and test set
  8.  
  9. rf_train_pred = classifier.predict(X_train)
  10. rf_test_pred = classifier.predict(X_test)
  11.  
  12. training_score = classifier.score(X_train, y_train)
  13. test_score = classifier.score(X_test, y_test)
  14.  
  15. print("Has a training accuracy of {} % ".format(round(training_score.mean(), 5) * 100))
  16. print("Has a test accuracy of {} % ".format(round(test_score.mean(), 5) * 100))
  17. # The accuracy score on its own is less useful for classification. Need to check the confusion matrix
  18. # Notice how severe the overfitting is
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement