Running your first program on Google

artificial intelligence: Colaboratory



AD

Pima Indians Diabetes deep learning program to test Colab

The online GPU (Graphical Processing Unit) capabilities include processing Keras, and TensorFlow environments. Google's site is called Google Colaboratory and is available on Google Drive. Google Drive is free when when you sign up for a google account. You get a Google account when you sign up for a Google email address, which is also free. On this page we will describe how to run a sample program. There are two more pages that describe how to install Colab, and how the program works. These are introductory tutorials.The deep learning program we use in the tutorial is written in Python. You can follow my Python tutorial if you so desire. Keras is built in Python.



Download the pima-indians-diabetes.csv database to your computer.

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 ninth value is a 0 or 1 for diabetes. We will explain in detail in the third segment of this tutorial.

2. Download the pima-indians-diabetes.csv dataset to your computer from https://networkrepository.com/pima-indians-diabetes.php . Just click the download button to save to Downloads on your computer. This works for Windows and Linux.



The program

3. The following program is to be copy and pasted into the Colab window.

# 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))



Putting code in the Colab window

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.

4. Access the Colab interface. From Google Drive, click on the New button, and scroll down to Colaboratory. Click on Colaboratory and it will open.

Colaboratory home page

5. Click on the Code button to open a blank line for your code.
Copy and paste the above code into the Colab code window.
Use Control+v to paste.

Copy and paste program to Colab

6. Click on the Code button again to open a blank line below the pasted code. We will type in the code to upload the pima-indians-diabetes.csv file. Type the following:

from google.colab import files
uploaded = files.upload()



Running the code

7. Click the arrow next to the code to run the upload program. A box will open for you. Browse for the pima-indians-diabetes.csv file. (It is in your Downloads folder on your computer.) The file will upload to Colab.

Colab uploaded database file

8. You are now ready to run the pasted program. Click the arrow next to the code to run the program. About a hundred lines of output will scroll down, with a final percent accuracy for determining whether or not a person will develop onset diabetes. If you make a mistake running the programs, you will need to clear the output. Go to Edit->Clear all outputs.

Colab program results

9. You can now save your work. File->Save a copy in Drive. (Drive is the 15GB storage area that Google provides for you free of charge.)

10. If you want to clear your output. Go to Edit->Clear all outputs.

11. To restart your session after it has closed, go to Drive and double click on the Colab file.

Colaboratory page



Renaming your project from the default

12. One way to rename your project from the default is to click on the name, and rename it. Another way you can rename your project file, is in Google Drive. After is is saved, just right click on the project name and click rename.




Congratulations! Google Colaboratory is installed. You ran your first program! Note that Colab works on both Windows and Linux computers once installed.





If you wish to continue the tutorial there are links to two more Colab pages under the Python Navigation column. The first page describes installation of Colab. The third page describes the program in detail. Knowledge of Python is assumed for the detailed description.



theSurfDragon.com

AI Homepage

Colab Navigation

SALARSEN.COM
Python Tutorial
Install Colab
Colab Example
Example Details