text_html_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import confusion_matrix

from sklearn.metrics import confusion_matrix

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

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)

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

TN = cm[0, 0]
TP = cm[1, 1]
FN = cm[1, 0]
FP = cm[0, 1]
sensitivity = TP / float(TP + FN)
specificity = TN / float(TN + FP)

print('The accuracy of the model = TP+TN/(TP+TN+FP+FN) = ', (TP + TN) / float(TP + TN + FP + FN), '\n', 'The Missclassification = 1-Accuracy = ', 1 - (TP + TN) / float(TP + TN + FP + FN), '\n', 'Sensitivity or True Positive Rate = TP/(TP+FN) = ', TP / float(TP + FN), '\n', 'Specificity or True Negative Rate = TN/(TN+FP) = ', TN / float(TN + FP), '\n', 'Positive Predictive value = TP/(TP+FP) = ', TP / float(TP + FP), '\n', 'Negative predictive Value = TN/(TN+FN) = ', TN / float(TN + FN), '\n', 'Positive Likelihood Ratio = Sensitivity/(1-Specificity) = ', sensitivity / (1 - specificity), '\n', 'Negative likelihood Ratio = (1-Sensitivity)/Specificity = ', (1 - sensitivity) / specificity)