application_vnd.jupyter.stderr_output_2.png text_plain_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import precision_score, recall_score, f1_score,accuracy_score #metrics

from sklearn.metrics import roc_auc_score, roc_curve #metrics

from sklearn.neighbors import KNeighborsClassifier

import numpy as np

import pandas as pd

data = pd.read_csv('../input/stroke-prediction-dataset/healthcare-dataset-stroke-data.csv')

data.drop(['id'], axis=1, inplace=True)

data.isnull().sum()

data.isnull().sum()

strokes = len(data[data['stroke'] == 1])
no_strokes = data[data.stroke == 0].index
random_indices = np.random.choice(no_strokes, strokes, replace=False)
stroke_indices = data[data.stroke == 1].index
under_sample_indices = np.concatenate([stroke_indices, random_indices])
udata = data.loc[under_sample_indices]

from sklearn.linear_model import LogisticRegression
lr = LogisticRegression()
lr.fit(X_train, Y_train)

Y_pred = lr.predict(X_test)
features = np.array([[0, 78, 0, 0, 1, 3, 0, 60, 28.8, 1]])
prediction = lr.predict(features)

from sklearn.neighbors import KNeighborsClassifier
knn_classifier = KNeighborsClassifier(n_neighbors=3, metric='minkowski', p=3)
knn_classifier.fit(X_train, Y_train)

Y_pred_knn = knn_classifier.predict(X_test)
features = np.array([[0, 78, 0, 0, 1, 3, 0, 60, 28.8, 1]])
prediction = knn_classifier.predict(features)

print('Accuracy:', accuracy_score(Y_test, Y_pred_knn))
print('Precision', precision_score(Y_test, Y_pred_knn))
print('Recall', recall_score(Y_test, Y_pred_knn))
print('F1 score', f1_score(Y_test, Y_pred_knn))
print('ROC score', roc_auc_score(Y_test, Y_pred_knn))