import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
heart_data = pd.read_csv('../input/heart-disease-uci/heart.csv')
heart_data.head()
y = heart_data['target']
X = heart_data.drop('target', axis = 1)
X.head()
X.describe()
y.value_counts()
"""
Lets split our data
"""
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)

# keep in mind that we want to use scaler on a training data not on a test data. so before scaling we need to split our data

#we will use a standart scaler to scale the features for preprocessing

scaler = StandardScaler()
scale = scaler.fit(X_train)
#print(scale.mean_)
#print(scale.scale_)
X_train = scale.transform(X_train)

X_test = scale.transform(X_test)
model = LogisticRegression()
model.fit(X_train, y_train)
pred = model.predict(X_test)
score = accuracy_score(y_test, pred)
score
confusion_matrix(y_test, pred)
tn, tp, fn, fp = confusion_matrix(y_test, pred).ravel()
(tn, tp, fn, fp)
matrix = classification_report(y_test, pred)
print('Classification report \n', matrix)