<jupyter_start><jupyter_text>deep learning problem using kears and tensorflow<jupyter_code>import keras
import tensorflow<jupyter_output><empty_output><jupyter_text>diabetez prediction using ANN(keras)<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
col_names=["pregnant","glucose","bp","skin","insulin","bmi","pdegree","age","result"]
pima=pd.read_csv("D:/DATA SCIENCE NOTE/pima.csv",names=col_names)
pima.head(5)
#display the no of people diabets and without diabetes
N,Y=pima["result"].value_counts()
print("no of people who has no suffer from diabetic dieases",N)
print("no of people who has with suffer from diabetic dieases",Y)
#data visualization with countplot
import seaborn as sns
sns.countplot(pima["result"])
%matplotlib inline
font={"fontsize":15}
data=[Y,N]
plt.pie(data,labels=["diabets","NO diabetes"],colors=["blue","red"],autopct="%0.1f%%",shadow=True,radius=1.5,textprops=font)
plt.show()
#find the misiing values
pima.isnull().sum()
#handle the missing values
print("no of rows with zero glucose",len(pima.loc[pima['glucose']==0]))
print("no of rows with zero pregnant",len(pima.loc[pima["pregnant"]==0]))
print("no of rows with zero bp",len(pima.loc[pima["bp"]==0]))
print("no of rows with zero skin",len(pima.loc[pima["skin"]==0]))
print("no of rows with zero insulin",len(pima.loc[pima["insulin"]==0]))
print("no of rows with zero bmi",len(pima.loc[pima["bmi"]==0]))
print("no of rows with zero pdegree",len(pima.loc[pima["pdegree"]==0]))
print("no of rows with zero age",len(pima.loc[pima["age"]==0]))
#calculate the median value for bmi ,pdegree,insulin,skin,bp,pregnant,glucose
median_bmi=pima["bmi"].median()
#substitute the bmi column of the dataset where are 0 value arer present
pima["bmi"]=pima["bmi"].replace(to_replace=0,value=median_bmi)
pima["insulin"]=pima["insulin"].replace(to_replace=0,value=pima["insulin"].median())
pima["skin"]=pima["skin"].replace(to_replace=0,value=pima["skin"].median())
pima["bp"]=pima["bp"].replace(to_replace=0,value=pima["bp"].median())
pima["pregnant"]=pima["pregnant"].replace(to_replace=0,value=pima["pregnant"].median())
pima["glucose"]=pima["glucose"].replace(to_replace=0,value=pima["glucose"].median())
#separate the input and output value
X=pima.drop(columns=["result"])
Y=pima["result"]
X

Y
#standardise  or normalize the data by keeping in between si that min will be 0 and std deviatiobn 1
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
X=sc.fit_transform(X)

print(X)
#split the dataset into training and testing the dataset
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.2)
print(X_train.shape)
print(X_test.shape)
print(Y_train.shape)
print(Y_test.shape)
import keras
from keras.models import Sequential
from keras.layers import Dense
model=Sequential()
#now add the input and first hidden layer
#we have 8 inputs and let keedp 5 neurons in first hidden layers
model.add(Dense(units=5,input_dim=8,activation="relu"))

#add second hidden leyer
#lets say it contain 5 neurons 
model.add(Dense(units=5,activation="relu"))
#add output layer
#here the outputs is a binary i.e 0 and 1.hece in this  place we use sigmoid
#activation function and it contain one neuron
model.add(Dense(units=1,activation="sigmoid"))
#compile the keras moodel
model.compile(optimizer="adam",loss="binary_crossentropy",metrics=["accuracy"])
#fit keras model
model.fit(X_train,Y_train,epochs=150,batch_size=10)
#predict for X_test
Y_pred=model.predict(X_test)
Y_pred
Y_test.values
Y_pred=Y_pred>0.5
Y_pred
Y_pred=model.predict_classes(X_test)
Y_pred
#find accuracy
from sklearn.metrics import accuracy_score
acc=accuracy_score(Y_test,Y_pred)
acc=round(acc*100,2)
print("accuracy of this model is",acc)
#or evaluate the keras model
#evaluate() RETURNS 2 values loss and accuracy
__,acc=model.evaluate(X_test,Y_test)
print(acc)
#noe predict for an unknown person
import numpy as np
data=np.array([[8,48,72,45,0,35,0,65]])
X1=sc.transform(data)
X1
model.predict(X1)
model.predict_classes(X1)
#this is expalin about deep learning using an exapmle of diabetic prediction<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14677574590952838, 'fraction_numerical': 0.015399422521655439, 'mean_word_length': 8.874109263657957, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '200889', 'license': 'MIT', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1471, 'n_words': 353, 'path': 'Deep Learning explain using an example of diabetic prediction.ipynb', 'repo_name': 'patrasoumyaranjan1999/DEEP-LEARNING-EXPLAIN-USING-DIABETIC-PREDICTION', 'size': '4156'}