0% found this document useful (0 votes)
9 views3 pages

Prediction Using ANN

Uploaded by

agwonadavid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Prediction Using ANN

Uploaded by

agwonadavid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#Prediction using ANN

#importing libraries

import pandas as pd # data minupulation and analsysis

#import numpy as np # matrices, arrrays

from sklearn.preprocessing import LabelEncoder, StandardScaler # StandardScaler is used to


standardize dataset resources,

#LabelEncoder - used to encode categorical labels into numeric


values

from sklearn.model_selection import train_test_split # is used to split the dataset into training and test
sets

import tensorflow as tf #is a popular framework for building and training machine learning models

from tensorflow.keras import Sequential # is a sequential model where the layers are linearly stacked

from tensorflow.keras.layers import Dense # defines a dense (fully connected) layer of the neural
network

from tensorflow.keras.layers import Dropout # is used to add dropout layers to avoid overfitting

#Loading Data

data= pd.read_csv("diabetes.csv")

data.head()

#Splitting the data into training and testing sets

X = data.drop('Outcome', axis =1)

Y = data['Outcome']

Xtrain, xtest, Ytrain, ytest = train_test_split(X,Y, test_size =0.2)

# data has been splitted , 20% - testing and 80 training


#Standardized data

scaler = StandardScaler()

Xtrain = scaler.fit_transform(Xtrain)

xtest = scaler.transform(xtest)

#Creating training model

model = Sequential([

Dense(32, activation = 'relu', input_shape = (Xtrain.shape[1],)),

Dropout(0.1),

Dense(32, activation = 'relu'),

Dropout(0.5),

Dense(1, activation = 'sigmoid')

])

#Model Compilation and summary

model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])

model.summary()

#Training Model

model.fit(Xtrain, Ytrain, epochs = 10, batch_size = 16, validation_data = (xtest, ytest))

#Model Results

loss, accuracy = model.evaluate(xtest, ytest)


print(f'Test loss: {loss:.4f}')
print(f'Test accuracy: {accuracy:.4f}')

You might also like