# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

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

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.metrics import accuracy_score
"""
The Dataset
"""
diabetes_dataset = pd.read_csv('../input/diabetes-data-set/diabetes.csv')
"""
Exploratory Data Analysis
"""
diabetes_dataset.shape
diabetes_dataset.head()
diabetes_dataset.info()
diabetes_dataset.duplicated()
diabetes_dataset.describe()
import seaborn as sns
sns.boxplot(data=diabetes_dataset)
diabetes_dataset['Outcome'].value_counts().plot(kind='bar')
diabetes_dataset.groupby('Outcome').mean()
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=[10,6])
sns.heatmap(diabetes_dataset.corr(),annot=True)
"""
Separating Data and label columns
"""
X = diabetes_dataset.drop(columns='Outcome', axis=1)
Y = diabetes_dataset['Outcome']

print(X)
print(Y)
#Standard Scaler
scaler = StandardScaler()
scaler.fit(X)
standardized_data = scaler.transform(X)
print(standardized_data)
X = standardized_data
"""
Splitting into Train and Test sets
"""
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, stratify=Y, random_state=2)
"""
**Support Vector Machine**
"""
classifier = svm.SVC(kernel='linear')

classifier.fit(x_train, y_train)

x_train_prediction = classifier.predict(x_train)
training_data_accuracy = accuracy_score(x_train_prediction, y_train)
print(training_data_accuracy)

x_test_prediction = classifier.predict(x_test)
testing_data_accuracy = accuracy_score(x_test_prediction, y_test)
print(testing_data_accuracy)
"""
**Logistic Regression**
"""
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(x_train, y_train)

x_train_prediction = model.predict(x_train)
training_data_accuracy = accuracy_score(x_train_prediction, y_train)
print(training_data_accuracy)

x_test_prediction = model.predict(x_test)
testing_data_accuracy = accuracy_score(x_test_prediction, y_test)
print(testing_data_accuracy)
"""
**K Nearest Neighbor**
"""
from sklearn.neighbors import KNeighborsClassifier
model=KNeighborsClassifier(n_neighbors=50)
model.fit(x_train,y_train)

x_train_prediction = model.predict(x_train)
training_data_accuracy = accuracy_score(x_train_prediction, y_train)
print(training_data_accuracy)

x_test_prediction = model.predict(x_test)
testing_data_accuracy = accuracy_score(x_test_prediction, y_test)
print(testing_data_accuracy)
"""
**Decision Tree Classifier**
"""
from sklearn.tree import DecisionTreeClassifier
model=DecisionTreeClassifier()
model.fit(x_train,y_train)

x_train_prediction = model.predict(x_train)
training_data_accuracy = accuracy_score(x_train_prediction, y_train)
print(training_data_accuracy)

x_test_prediction = model.predict(x_test)
testing_data_accuracy = accuracy_score(x_test_prediction, y_test)
print(testing_data_accuracy)
"""
**Random Forest Classifier**
"""
from sklearn.ensemble import RandomForestClassifier
model=RandomForestClassifier()
model.fit(x_train,y_train)

x_train_prediction = model.predict(x_train)
training_data_accuracy = accuracy_score(x_train_prediction, y_train)
print(training_data_accuracy)

x_test_prediction = model.predict(x_test)
testing_data_accuracy = accuracy_score(x_test_prediction, y_test)
print(testing_data_accuracy)
model = ['Support Vector Machine', 'Logistic Regression', 'K Nearest Neighbor', 'Decision Tree Classifier', 'Random Forest Classifier']
train_score = [0.7866449511400652, 0.7850162866449512, 0.7687296416938111, 1.0, 1.0]
test_score = [0.7727272727272727, 0.7597402597402597, 0.7272727272727273, 0.7077922077922078, 0.7337662337662337]
pd.DataFrame({"model":model,"Train set accuracy":train_score, "Test set accuracy":test_score})