I am following this tutorials: https://www.datacamp.com/community/tutorials/random-forests-classifier-python on using Scikit-learn with random forests. However, the current code only shows the test accuracy whereas I want to know the training accuracy as well since may dataset is very small.
The code to get the test accuracy is:
from sklearn import metrics
print("Accuracy:", metrics.accuracy_score(y_test, y_pred))
How would I modify this to get the training accuracy?
y_train_pred = clf.predict(X_train)whereclfis your fittedRandomForestClassifier. After that you can usemetrics.accuracy_score(y_train, y_train_pred)to get the training accuracy. Alternatively, you can useclf.score(X_train, y_train), which should give you the same result.