user12587364
user12587364

Reputation:

Random Forest: How to get the training accuracy for comparison to test accuracy

In training a neural network, one can see the model performance during model fit and can easily see model accuracy on train set, such as:

Epoch 1/100
48000/48000 [==============================] - 6s - loss: 0.3747 - acc: 0.8732 - val_loss: 0.2888 - val_acc: 0.8935
Epoch 2/100
48000/48000 [==============================] - 6s - loss: 0.2216 - acc: 0.9178 - val_loss: 0.2942 - val_acc: 0.9010

I'm not referring on train verbose either. But some way of knowing what the accuracy is on the train set.

In the code below, we train a random forest classifier and get its accuracy on the train set. How about accuracy on train?

model.fit(train_set, y_train)

y_pred = model.predict(test_set)
print("Accuracy:",accuracy_score(y_test, y_pred))

Upvotes: 0

Views: 2293

Answers (1)

Danylo Baibak
Danylo Baibak

Reputation: 2316

Just use your train_set as an input for prediction:

model.fit(train_set, y_train)

pred_train = model.predict(train_set)
pred_test = model.predict(test_set)

print("Accuracy train: ", accuracy_score(y_train, pred_train))
print("Accuracy test: ", accuracy_score(y_test, pred_test))

Upvotes: 1

Related Questions