text_plain_output_1.png image_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import confusion_matrix

from sklearn.metrics import confusion_matrix

from sklearn.model_selection import cross_val_predict

from sklearn.model_selection import cross_val_score

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df = pd.read_csv('../input/heartdisease-dataset/heart.csv')

df.drop(['exang'], axis=1, inplace=True)

df[df['age'] >= 50]['target'].value_counts() * 100 / df.shape[0]

df[df['age'] < 50]['target'].value_counts() * 100 / df.shape[0]

X = df.iloc[:, :12]
y = df.iloc[:, 12]

from sklearn.ensemble import RandomForestClassifier
rf_model = RandomForestClassifier(n_estimators=100)
rf_predictions = cross_val_predict(rf_model, X, y, cv=5)
print(confusion_matrix(y, rf_predictions))
rf_scores = cross_val_score(rf_model, X, y, scoring='recall', cv=5)
print('recall:', rf_scores.mean())