text_plain_output_1.png image_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import confusion_matrix

from sklearn.metrics import confusion_matrix

from sklearn.preprocessing import binarize

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import sklearn

df = pd.read_csv('../input/framingham.csv')
df.drop(['education'], axis=1, inplace=True)

df.rename(columns={'male': 'Sex_male'}, inplace=True)

df.isnull().sum()

count = 0
for i in df.isnull().sum(axis=1):
    count = count + 1

df.dropna(axis=0, inplace=True)

def draw_histograms(dataframe,features,rows,cols):
    fig = plt.figure(figsize = (20,20))
    for i, feature in enumerate(features):
        a = fig.add_subplot(rows,cols,i+1)
        dataframe[feature].hist(bins = 20,ax=a,facecolor = 'green')
        a.set_title(feature + "Distribution",color = 'blue')
    fig.tight_layout()
    plt.show()
draw_histograms(df,df.columns,6,3)

df.TenYearCHD.value_counts()

lgr = LogisticRegression()
lgr.fit(x_test, y_test)
y_pred = lgr.predict(x_test)

sklearn.metrics.accuracy_score(y_test, y_pred)

cm = confusion_matrix(y_test, y_pred)
conf_matrix = pd.DataFrame(data=cm, columns=['Predicted:0', 'Predicted:1'], index=['Actual:0', 'Actual:1'])

y_pred_prob = lgr.predict_proba(x_test)[:, :]
y_pred_prob_df = pd.DataFrame(data=y_pred_prob, columns=['No Heart Disease (0)', 'Heart Disease (1)'])

for i in range(1, 5):
    cm2 = 0
    y_pred_prob_yes = lgr.predict_proba(x_test)
    y_pred2 = binarize(y_pred_prob_yes, i / 10)[:, 1]
    cm2 = confusion_matrix(y_test, y_pred2)

sklearn.metrics.roc_auc_score(y_test, y_pred_prob_yes[:, 1])