# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="-OCk3-F8TBt_" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596631267437, "user_tz": -330, "elapsed": 1213, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="d0cf1aee-aa92-4da4-8046-d9cd7bb784e8"
# cd /content/drive/My Drive/Dava with ML

# + id="4bVgsMd9T-u9" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1590300830471, "user_tz": -330, "elapsed": 5329, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="7bd05b9a-5eb1-40dd-a0d2-9085a1ecca0a"
# !unzip pima-indians-diabetes-database.zip

# + id="cUzTrdMsUKfa" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 70} executionInfo={"status": "ok", "timestamp": 1596631270504, "user_tz": -330, "elapsed": 1765, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="ca367911-a7c1-42e4-e354-73ded53feda9"
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
import sklearn.metrics as m

# + id="KvHucVWpgD7s" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 386} executionInfo={"status": "ok", "timestamp": 1596631274371, "user_tz": -330, "elapsed": 5052, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="f60cebb7-23e4-4d93-a9d5-c8c377e3b4eb"
# ls

# + id="XUQIfEVohqE7" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 402} executionInfo={"status": "ok", "timestamp": 1596631275301, "user_tz": -330, "elapsed": 5502, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="abf87cf8-3d86-45c6-825a-d3730bb2f194"
dataset=pd.read_csv('diabetes.csv')
dataset

# + id="gX7YvIZNhwn5" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596631275302, "user_tz": -330, "elapsed": 5030, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="156153e3-e6ba-401b-f47f-10c03a42068b"
dataset.isnull().values.any()

# + id="2WSNBwdbEzCx" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 594} executionInfo={"status": "ok", "timestamp": 1596631276667, "user_tz": -330, "elapsed": 5969, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="3e9f6029-8513-453c-882f-24783345efd7"
plt.figure(figsize=(30,15))
sns.heatmap(dataset.corr(),annot=True)
plt.show()

# + id="Ok-nYEj27oGl" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 296} executionInfo={"status": "ok", "timestamp": 1596631276668, "user_tz": -330, "elapsed": 5590, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="e44fde1d-a508-4c41-8da5-4e4bfca8befe"
sns.countplot(x='Outcome',data=dataset)

# + id="ytDtv6qQAzOR" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 594} executionInfo={"status": "ok", "timestamp": 1596631277721, "user_tz": -330, "elapsed": 6221, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="8812c224-9191-4fbb-bda4-83a861e3038e"
plt.figure(figsize=(30,15))
sns.heatmap(dataset.corr(),annot=True)
plt.show()

# + [markdown] id="iWk_mNeT7iIB" colab_type="text"
# ##Splitting Dataset

# + id="f0O2ii2YE2tG" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631277722, "user_tz": -330, "elapsed": 5138, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
features=dataset.iloc[:,:-1]
labels=dataset.iloc[:,[-1]]

# + id="_GUMUiTd79ir" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631277722, "user_tz": -330, "elapsed": 4578, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
features=np.array(features)

# + id="NASocfK-7_aP" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631277723, "user_tz": -330, "elapsed": 2707, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}


# + id="moZ58Nsd8Awm" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631277724, "user_tz": -330, "elapsed": 2074, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
feature_train,feature_test,label_train,label_test=train_test_split(features,labels,test_size=0.2,random_state=42)

# + id="34Y8vi1d8XwB" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596631277724, "user_tz": -330, "elapsed": 1509, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="7ed92c33-324f-4eab-d047-3cdb3a27cd29"
feature_train

# + [markdown] id="iCq5anyc8dhQ" colab_type="text"
# ##Logistic Regression

# + id="ZYDsYMJA8ZIz" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 154} executionInfo={"status": "ok", "timestamp": 1596477321108, "user_tz": -330, "elapsed": 1301, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="e65b4462-c552-4d87-c0ff-c1c0de0e8202"
model=LogisticRegression(max_iter=300)
model.fit(feature_train,label_train)

# + id="dsxXQkXW8nuc" colab_type="code" colab={}
label_pred=model.predict(feature_test)

# + id="l6PEUF299C89" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596477325540, "user_tz": -330, "elapsed": 688, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="88ca409b-bbff-4bd9-f8a0-4bdf4ea65a03"
m.accuracy_score(label_test,label_pred)

# + id="JalYExvC9RBH" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596477327786, "user_tz": -330, "elapsed": 1066, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="878d5f5a-0059-4d03-fba5-912ff251ef45"
label_pred

# + id="diY8PaHi9gK9" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 402} executionInfo={"status": "ok", "timestamp": 1596477328238, "user_tz": -330, "elapsed": 738, "user": {"displayName": "<NAME>sh", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="4ad6f4af-049a-4140-e829-1c868d6c2952"
label_test

# + id="i_zSzdIf9h94" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 168} executionInfo={"status": "ok", "timestamp": 1596477329795, "user_tz": -330, "elapsed": 1464, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="1f19fb50-b255-44e1-bc85-9b93acaafc4d"
print(m.classification_report(label_test,label_pred))

# + id="1v2eFWz897CP" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1596477330218, "user_tz": -330, "elapsed": 1003, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="1e5b7175-33bb-4642-8c5b-560d142cb508"
print(m.confusion_matrix(label_test,label_pred))

# + [markdown] id="3D1TJdYi-FL5" colab_type="text"
# ##KNN

# + id="6-sT8gdt-A6T" colab_type="code" colab={}
from sklearn.model_selection import GridSearchCV
knn=KNeighborsClassifier()
param={'n_neighbors':list(np.arange(1,20))}


# + id="n6nU7BJO-OBA" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} executionInfo={"status": "ok", "timestamp": 1596477335246, "user_tz": -330, "elapsed": 1576, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="1be6d4fb-1b51-4030-d909-2e208171a7ff"
model=GridSearchCV(knn,param_grid=param)
model.fit(feature_train,label_train)

# + id="glt1M5eM-QIQ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596477337599, "user_tz": -330, "elapsed": 1090, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="7d019d49-1325-4977-cd31-c3cac4745c01"
model.best_params_

# + id="q3pRIhod-UQN" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 121} executionInfo={"status": "ok", "timestamp": 1596477350920, "user_tz": -330, "elapsed": 1266, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="0ba8ff18-fe54-470c-e167-acd4ea6fbad6"
model=KNeighborsClassifier(n_neighbors=8)
model.fit(feature_train,label_train)

# + id="agQF8OB--uf-" colab_type="code" colab={}
label_pred=model.predict(feature_test)

# + id="0v5qp_56-4AV" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596477351528, "user_tz": -330, "elapsed": 1005, "user": {"displayName": "<NAME>amesh", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="dd81f1af-bec3-4023-da77-a282af852d1c"
label_pred

# + id="IBUiVzbO-5Fk" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596477353132, "user_tz": -330, "elapsed": 765, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="97cd4e5b-99b3-41b6-da2a-595db7096bf6"
m.accuracy_score(label_test,label_pred)

# + id="m_dfg0je--PE" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 168} executionInfo={"status": "ok", "timestamp": 1596477386631, "user_tz": -330, "elapsed": 1607, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="b02b623c-4d93-41b2-8c0f-908a83644d8a"
print(m.classification_report(label_test,label_pred))

# + id="mRN-9gRR_KuB" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1596477386634, "user_tz": -330, "elapsed": 1358, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="384e0968-20d7-455b-f92b-8b2cb7ae9834"
print(m.confusion_matrix(label_test,label_pred))

# + [markdown] id="Xx8bj2UT_i8V" colab_type="text"
# ##Decision Tree

# + id="HfhuCmZa_fmq" colab_type="code" colab={}
from sklearn.model_selection import GridSearchCV
dt=DecisionTreeClassifier()
param={'max_depth':list(np.arange(1,20))}


# + id="idl_ilFz_psQ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 319} executionInfo={"status": "ok", "timestamp": 1596477388791, "user_tz": -330, "elapsed": 1416, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="116e47c9-ddd3-4bad-beea-96111de5308f"
model=GridSearchCV(dt,param_grid=param)
model.fit(feature_train,label_train)

# + id="IJ7-OJ_5_sTj" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596477391014, "user_tz": -330, "elapsed": 1121, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="10194de4-971a-4cb9-e63c-799e77c4ad1f"
model.best_params_

# + id="KxUttILe_vHs" colab_type="code" colab={}
model=model.best_estimator_

# + id="IipE1ppS_x6R" colab_type="code" colab={}
label_pred=model.predict(feature_test)

# + id="8Kl57nm2_2vt" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596477395044, "user_tz": -330, "elapsed": 1156, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="9ad54730-247d-4c85-8a1f-03f735fe547d"
label_pred

# + id="_CK5s8rc_38p" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596477395520, "user_tz": -330, "elapsed": 982, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="b1ecfadd-554c-4629-d41c-d02dd4cf4819"
m.accuracy_score(label_test,label_pred)

# + id="tCNDHeHxAMiv" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 168} executionInfo={"status": "ok", "timestamp": 1596477399922, "user_tz": -330, "elapsed": 1313, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="cdbe2ea7-79a0-470a-e62b-907430833cab"
print(m.classification_report(label_test,label_pred))

# + id="kM2Rn5KOAZDa" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1596477399927, "user_tz": -330, "elapsed": 1020, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="bfb595f5-7f1b-44db-9fec-a66ee92e1ac1"
print(m.confusion_matrix(label_test,label_pred))

# + [markdown] id="QbgkL3LaBMxb" colab_type="text"
# ##SVM

# + id="ycy7J3piAfD1" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 138} executionInfo={"status": "ok", "timestamp": 1596477411597, "user_tz": -330, "elapsed": 4936, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="b4a11f0b-2f00-4edd-d669-529a471f88cd"
model=SVC(kernel='linear')
model.fit(feature_train,label_train)

# + id="iWqonh9eBYSv" colab_type="code" colab={}
label_pred=model.predict(feature_test)

# + id="zKnww4B-BdP9" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596477413524, "user_tz": -330, "elapsed": 1263, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="75cc3d14-a603-4619-83f6-b016d16c2ffa"
m.accuracy_score(label_test,label_pred)

# + id="TxFTEhHaBf90" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 168} executionInfo={"status": "ok", "timestamp": 1596477416033, "user_tz": -330, "elapsed": 1285, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="47bc1737-ff85-49f2-9731-545d2834ea76"
print(m.classification_report(label_test,label_pred))

# + id="1dUqC7kdB1zs" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1596477416037, "user_tz": -330, "elapsed": 870, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="ecdc540d-f4a8-410a-9a18-5cd49236c7dc"
print(m.confusion_matrix(label_test,label_pred))

# + id="Ss_0OYL8B4Y2" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596477418389, "user_tz": -330, "elapsed": 750, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="d2a2d110-4484-42b0-f875-38791ec4935f"
label_pred

# + id="ZRduREsNB5yK" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 402} executionInfo={"status": "ok", "timestamp": 1596477420092, "user_tz": -330, "elapsed": 690, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="fa7260ba-ae24-4cf7-cd14-30fc223ab094"
label_test

# + [markdown] id="Fxf70cDRCBEH" colab_type="text"
# ## Random Forest Classifier

# + id="7jtHTo6tB7J5" colab_type="code" colab={}
from sklearn.model_selection import GridSearchCV
rfc=RandomForestClassifier()
param={'n_estimators':[50,100,150,200],'max_depth':list(np.arange(1,20))}


# + id="Gq9kSdHiCI_D" colab_type="code" colab={}
model=GridSearchCV(rfc,param_grid=param)
model.fit(feature_train,label_train)

# + id="ec7Jv5-PCLPk" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1590386071026, "user_tz": -330, "elapsed": 917, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="0923f439-5a81-485a-d61d-ba68c7f516a6"
model.best_params_

# + id="w6EUn7VYD9mB" colab_type="code" colab={}
model=model.best_estimator_

# + id="8WtAQlCZD_zf" colab_type="code" colab={}
label_pred=model.predict(feature_test)

# + id="jCYdcC-0EEUf" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1590386075409, "user_tz": -330, "elapsed": 811, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="064cd684-78a4-4bee-8126-e683b9a50c13"
label_pred

# + id="8g_sCN4FEFcJ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1590386076877, "user_tz": -330, "elapsed": 607, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="833aad74-44ef-41ec-bdb0-ed01c7b5c32c"
m.accuracy_score(label_test,label_pred)

# + id="EVeQq87AEISn" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 168} executionInfo={"status": "ok", "timestamp": 1590386086745, "user_tz": -330, "elapsed": 6324, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="cc41526b-cbf5-46a3-c1dc-3fa212a8dde0"
print(m.classification_report(label_test,label_pred))

# + id="3cl-WG-EEPSq" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1590386086747, "user_tz": -330, "elapsed": 6095, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="8408c7d3-967d-499a-f3a3-ee2ccde8f52f"
print(m.confusion_matrix(label_test,label_pred))

# + id="HQX9QlRZER7W" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1590386086748, "user_tz": -330, "elapsed": 4159, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="239f9d08-5fe7-49f5-d352-119eb8311c96"
label_pred

# + id="7T2egeSOEW0l" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 402} executionInfo={"status": "ok", "timestamp": 1590386086749, "user_tz": -330, "elapsed": 3930, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="08ac5459-0e1f-45c2-c13a-17c8305f4185"
label_test

# + id="6CwX0MmueFTl" colab_type="code" colab={}


# + [markdown] id="70lm3Yz9eFoi" colab_type="text"
# #Nueral Network

# + id="v8wMuoMOEX-_" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631286399, "user_tz": -330, "elapsed": 2273, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential

# + id="yfESmuJjH4Uo" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631286399, "user_tz": -330, "elapsed": 2049, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
from keras.utils.np_utils import to_categorical
label_train=to_categorical(label_train)
label_test=to_categorical(label_test)

# + id="WwOlOwsQg1yl" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} executionInfo={"status": "ok", "timestamp": 1596631286400, "user_tz": -330, "elapsed": 1728, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="04eeb86d-307b-46be-af86-644c46aa1fbf"
label_test

# + id="rcR7t65ZhA8l" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596631286970, "user_tz": -330, "elapsed": 814, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="c1c840b7-e4b5-41cd-fd6e-08b673d702af"
feature_train.shape

# + id="KJ1EU7vuGi4s" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631293502, "user_tz": -330, "elapsed": 6457, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
model=Sequential()
model.add(Dense(400,input_shape=[8],activation='relu'))


model.add(Dense(2,activation='sigmoid'))
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])

# + id="-nPjOwujHC2m" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 218} executionInfo={"status": "ok", "timestamp": 1596631293507, "user_tz": -330, "elapsed": 4754, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="e4eda94f-3d8e-4ed3-8622-9ebc44558dd2"
model.summary()

# + id="N3ZgI-DUHZfU" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} executionInfo={"status": "ok", "timestamp": 1596631329473, "user_tz": -330, "elapsed": 38244, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="ff7c40ef-3226-4a63-d431-fb20becd6ac5"
model.fit(feature_train,label_train,epochs=500)

# + colab_type="code" id="yo4O0WVgHt7H" colab={} executionInfo={"status": "ok", "timestamp": 1596631449687, "user_tz": -330, "elapsed": 1232, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
label_pred=model.predict(feature_test)

# + id="jH3QimRiHxoS" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} executionInfo={"status": "ok", "timestamp": 1596631449687, "user_tz": -330, "elapsed": 984, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="c644b43c-5d55-4105-a17c-86e0644afc81"
label_pred

# + id="ep3WnxSXIPA1" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631449688, "user_tz": -330, "elapsed": 731, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
label_pred=np.argmax(label_pred,axis=1)

# + id="lphr8u7vIVFz" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596631452524, "user_tz": -330, "elapsed": 1286, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="b701822f-e741-4841-86a2-b97f7f220e60"
label_pred

# + id="bF0o9t3JIYv8" colab_type="code" colab={} executionInfo={"status": "ok", "timestamp": 1596631453025, "user_tz": -330, "elapsed": 1282, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}}
label_test=np.argmax(label_test,axis=1)
label_train=np.argmax(label_train,axis=1)

# + colab_type="code" id="k2jgZ12YHt7Y" colab={"base_uri": "https://localhost:8080/", "height": 34} executionInfo={"status": "ok", "timestamp": 1596631453025, "user_tz": -330, "elapsed": 705, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="d145e70f-700f-4792-b4c6-c2a293ae29ff"
m.accuracy_score(label_test,label_pred)

# + colab_type="code" id="hGgqpn3DHt7h" colab={"base_uri": "https://localhost:8080/", "height": 168} executionInfo={"status": "ok", "timestamp": 1596631458915, "user_tz": -330, "elapsed": 1252, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="0cf304f4-4ef8-41be-f514-8aed2f2b6b13"
print(m.classification_report(label_test,label_pred))

# + colab_type="code" id="NIoj3cocHt7p" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1596631460867, "user_tz": -330, "elapsed": 1258, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="1fcb7e1d-08a2-48fc-ec74-47cc6b7bc2f4"
print(m.confusion_matrix(label_test,label_pred))

# + colab_type="code" id="dyDuZuNSHt7y" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596631464864, "user_tz": -330, "elapsed": 1092, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="8120b70f-1204-48df-f664-cea864307eec"
label_pred

# + colab_type="code" id="6j1-UgcHHt75" colab={"base_uri": "https://localhost:8080/", "height": 134} executionInfo={"status": "ok", "timestamp": 1596631465322, "user_tz": -330, "elapsed": 606, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="b972e53c-3e86-4aa6-dd11-f22c4f4ef8fc"
label_test

# + id="qzt51bFAIpI_" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 154} executionInfo={"status": "ok", "timestamp": 1596631469525, "user_tz": -330, "elapsed": 3318, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="21a97595-1db4-42d3-8921-a4c02d9eca1b"
import tensorflow

#Save the model to saved_model.pbtxt

tensorflow.keras.models.save_model(model,'saved_model_liver.pbtxt')

# + id="sXvVoZMoptBi" colab_type="code" colab={}
model.save(model)

# + id="hUrdaX3dQKzQ" colab_type="code" colab={}
# We need to create a TFLite Converter Object from model we created

converter = tensorflow.lite.TFLiteConverter.from_keras_model(model=model)

# + id="sP4YeOIUQPHB" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 50} executionInfo={"status": "ok", "timestamp": 1596477653021, "user_tz": -330, "elapsed": 1529, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjTjqAs_XSPRluT1e_1a161LYmq1xxzr4Q-wY37=s64", "userId": "02067056678749702267"}} outputId="121dd6e5-729a-4946-d2ae-2d308c1f21fd"
# Create a tflite model object from TFLite Converter

tfmodel = converter.convert()

# Save TFLite model into a .tflite file 

open("degree_diabeties.tflite","wb").write(tfmodel)

# + id="B4SPHpSYQVFR" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered