# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: tensorflow_env
#     language: python
#     name: tensorflow_env
# ---

# ## Keras Assignment - Diabetes Dataset 

"""
A. Build a sequential model using Keras on top of this Diabetes dataset to find out if the
patient has diabetes or not, using ‘Pregnancies’, ‘Glucose’ & ‘BloodPressure’ as
independent columns.
a. This model should have 1 hidden layer with 8 nodes
b. Use Stochastic Gradient as the optimization algorithm
c. Fit the model, with number of epochs to be 100 and batch size to be 10
B. Build another sequential model where ‘Outcome’ is the dependent variable and all
other columns are predictors.
a. This model should have 3 hidden layers with 16 nodes in each layer
b. Use ‘adam’ as the optimization algorithm
c. Fit the model, with number of epochs to be 150 and batch size to be 10
"""

import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense

diabetes = pd.read_csv("C:\\Users\\black\\Desktop\\ai_py\\datasets\\diabetes.csv")

diabetes

# ### Selecting independent and dependent variables for model_1 

X = diabetes.iloc[:,:3]
X.shape

y = diabetes.iloc[:,8:9]
y.shape

# ### Splitting data into train and test sets 

X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=.7, random_state=40)

# ### Building, optimizing and fitting model_1 

model_1 = Sequential()
model_1.add(Dense(8, activation="relu", input_dim=3))
model_1.add(Dense(1,activation="softmax"))

model_1.compile(optimizer="sgd", loss="binary_crossentropy")

model_1.fit(X_train, y_train, epochs=100, batch_size=10)

# ### Selecting independent and dependent variables for model_2 

X = diabetes.iloc[:,:8]
X.shape

y = diabetes.iloc[:,8:9]
y.shape

# ### Splitting data into train and test sets 

X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=.7, random_state=40)

# ### Building, optimizing and fitting model_2 

model_2 = Sequential()
model_2.add(Dense(16, activation="relu", input_dim=8))
model_2.add(Dense(16, activation="relu"))
model_2.add(Dense(16, activation="relu"))
model_2.add(Dense(1,activation="softmax"))

model_2.compile(optimizer="adam", loss="binary_crossentropy")

model_2.fit(X_train, y_train, epochs=150, batch_size=10)

StarcoderdataJupyterScriptsDedupFiltered