text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score

from sklearn.metrics import confusion_matrix, precision_score, plot_confusion_matrix

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

best_score = -1
best_estimators = 0
for i in range(10, 250):
    model = RandomForestClassifier(n_estimators=i, random_state=0)
    model.fit(train_x, train_y)
    pred = model.predict(test_x)
    score = accuracy_score(pred, test_y)
    if score > best_score:
        best_score = score
        best_estimators = i

model = RandomForestClassifier(n_estimators=best_estimators, random_state=0)

model.fit(train_x, train_y)

pred = model.predict(test_x)
score = accuracy_score(pred, test_y)

from sklearn.metrics import confusion_matrix, precision_score, plot_confusion_matrix
import matplotlib.pyplot as plt
print('True Negatives: %d, False Positives: %d, False Negatives: %d, True Positives: %d' % tuple(confusion_matrix(test_y, pred).ravel()))
print('Precision Score: %f' % (precision_score(test_y, pred) * 100))
plot_confusion_matrix(model, test_x, test_y, cmap=plt.cm.Reds)
plt.title('Confusion Matrix')
plt.show()