text_html_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import confusion_matrix

from sklearn.model_selection import GridSearchCV

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_csv('../input/heart-disease-detection/heart_disease.csv')

df.columns

df.shape

df.isnull().sum()

df.describe().T

import seaborn as sns

import matplotlib.pyplot as plt

df.corr()

df.drop(columns='age', inplace=True)

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
x_train = scaler.fit_transform(x_train)
x_test = scaler.transform(x_test)

from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier
rf_model = RandomForestClassifier()
rf_params = {'n_estimators': [5, 50, 250], 'max_depth': [2, 4, 8, 16, 32, None]}
cv = GridSearchCV(rf_model, rf_params, cv=5)
cv.fit(x_train, y_train)

rf_model = RandomForestClassifier(max_depth=8, n_estimators=50)
rf_model.fit(x_train, y_train)
rf_model.score(x_test, y_test)

rf_pred = rf_model.predict(x_test)

from sklearn.metrics import confusion_matrix
plt.figure(figsize=(10, 10))
cf_matrix = confusion_matrix(y_test, rf_pred)
sns.heatmap(cf_matrix, annot=True, annot_kws={'size': 25})
plt.show()