Chapter 3 - Copy, Paste, and Modify a Program

Using Notepad



AD

We are going to copy and paste the following program into notepad to create a Python machine learning program.

# first neural network with keras tutorial
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
# load the dataset
dataset = loadtxt('pima-indians-diabetes.csv', delimiter=',')
# split into input (X) and output (y) variables
# 0-8 are dependent variables- 8th column not included
X = dataset[:,0:8]
# 8 column is independent variable
y = dataset[:,8]
# define the keras model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit the keras model on the dataset
model.fit(X, y, epochs=150, batch_size=16)
# evaluate the keras model
# Use _, to get last item from iteration
_, accuracy = model.evaluate(X, y)
print('Accuracy: %.2f'% (accuracy*100))

First copy and paste a copy of the program into notepad. This is the working copy, which we will make changes to. Save as testworking.txt to your Documents directory.

In Chapter 4 we will create the final copy of the program. Open testworking.txt. (Make any changes.) Save as “testfinal.py” The quotes are necessary to prevent the file being saved as a txt file. We now have the machine learning program testfinal.py.





theSurfDragon.com


Win-Conda Navigation

Table of Contents
Ch1-Installation
Ch2-Conda Navigator
Ch3-Notepad Editor
Ch4-Run a Program
Ch5-Program Explained