In this series of tutorials we will download, and install Anaconda and Jupyter. We will configure Anaconda-Navigator for deep learning. This includes installation of Python3, TensorFlow, and Keras. We will test the installation with the Hello World of deep learning, the pima-indians-diabetes database.
We assume you have completed Part I and Part II on Anaconda installation. In this tutorial we will install and configure Jupyter, which comes as part of the Anaconda-Navigator installation. Jupyter is where you write the programs. Anaconda-Navigator button will be present in your desktop. Navigator is configured for Deep Learning with Python3, Tensor-Flow, and Keras. We will start the tutorial by downloading the pima-indians-diabetes.csv database. We will use the database in the program I provide to test the Jupyter Notebook.
1. This program is the Hello World program for testing deep learning programs. The pima-indians-diabetes database is used to predict whether or not a person will develop diabetes. The database consists of about a thousand lines. Each line contains eight values for traits related to diabetes for a person. The nineth value is 0 or 1 for diabetes. We will explain in detail in the Program Details.
2. Download the pima-indians-diabetes.csv dataset to your computer from https://networkrepository.com/pima-indians-diabetes.php . Just click the green download button to save to Downloads on your computer.
3. Open the Anaconda-Navigator Home page with the desktop launcher.
4. Select Environments. Select env1.
5. Select Home. Launch Jupyter Notebook.
6. We can open Jupyter Notebook any time from Navigator by going to Environments->env1->Open with Jupyter Notebook.
7. Jupyter Notebook will open. (Remember that this is Jupyter Notebook with env1, that includes Python3, TensorFlow, and Keras.) Jupyter consists of two pages. A Home page, where we are now; and a code page.
8. From the Home page navigate to New->Notebook->Python3.
9. The Jupyter code page will open, with an open line to place code.
10. We will test Jupyter to see if everything is working properly. Type import Keras, and click on Run. If everything is working properly, you will see a blank line. If errors codes appear, we have a problem. We can now continue with pima-indians-diabetes test program.
import Keras
11. At the beginning of the tutorial we downloaded the pima-indians-diabetes.csv database. We will now copy and paste the following code into the code window. Essentially the program determines the probability that a person will get diabetes given a set of initial conditions. For a more detailed analysis https://thesurfdragon.com/AI/details-of-program-for-your-first-artificial-intelligence-program/index.html.
Note: I strongly suggest getting the PDF copy of Deep Learning With Python Develop Deep Learning Models on Theano and TensorFlow Using Keras by Jason Brownlee. It is thorough and easy to understand.
# 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))
12. After pasting the code from here to Jupyter Notebook, we must change the dataset path. The program lines should now be similar to the following.(Instead of steve you will see your user name and your path.)
dataset = loadtxt('/home/steve/Downloads/pima-indians-diabetes.csv', delimiter=',')
We have completed the changes to the code.
13. We will now run the code. Several hundreds of lines of output will be listed on your screen with a final statement of accuracy. Your machine learning learning program worked. If not, check your code carefully, especially the paths. Google any error messages.
14. Save the work in the Notebook by clicking on the floppy disk icon in upper left of the toolbar. The Notebook file is also auto saved. Go to File > Close and Halt. You will return to the Home page. You can see the notebook name in a list of files and directories in the Home page. You can reopen a notebook by clicking on the file name.
15. You can change the name of the Notebook project at the top of the page by clicking on Untitled 0 and renaming the Notebook project.
16. The files are stored on your harddrive. The following is the location of my files, where your jupyter files end in .ipynb. /home/Untitled1.ipynb
SALARSEN.COM
Python Tutorial
Anaconda Linux Install I
Navigator Install II
Jupyter Install III
Program Details