Install Anaconda and Keras
Based on How to Setup a Python Environment for Machine Learning and Deep Learning with Anaconda.
Environment: Ubuntu 16.04, Miniconda
conda create -n 'py35-anaconda-keras' python=3.5
. activate py35-anaconda-keras
conda install anaconda
conda install theano
conda install -c conda-forge tensorflow
conda install -c conda-forge keras
Verify the installation of packages with the following codes in IPython console:
import numpy
print('numpy: %s' % numpy.__version__)
import scipy
print('scipy: %s' % scipy.__version__)
import matplotlib
print('matplotlib: %s' % matplotlib.__version__)
import pandas
print('pandas: %s' % pandas.__version__)
import statsmodels
print('statsmodels: %s' % statsmodels.__version__)
import sklearn
print('sklearn: %s' % sklearn.__version__)
import theano
print('theano: %s' % theano.__version__)
import tensorflow
print('tensorflow: %s' % tensorflow.__version__)
import keras
print('keras: %s' % keras.__version__)
Run ANN Demo
Based on Develop Your First Neural Network in Python With Keras Step-By-Step.
wget http://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data -O pima-indians-diabetes.csv
cat << EOF > pima.py
# Create your first MLP in Keras
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
numpy.random.seed(7)
# load pima indians dataset
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]
# create 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 model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
model.fit(X, Y, epochs=150, batch_size=10)
# evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
EOF
python pima.py