In [ ]:
%matplotlib inline
In [ ]:
import numpy as np
In [ ]:
from sklearn import datasets
https://keras.io/#installation
Install TensorFlow backend: https://www.tensorflow.org/install/
pip install tensorflow
Insall h5py (required if you plan on saving Keras models to disk): http://docs.h5py.org/en/latest/build.html#wheels
pip install h5py
Install pydot (used by visualization utilities to plot model graphs): https://github.com/pydot/pydot#installation
pip install pydot
pip install keras
In [ ]:
import tensorflow as tf
tf.__version__
In [ ]:
import keras
keras.__version__
In [ ]:
import h5py
h5py.__version__
In [ ]:
import pydot
pydot.__version__
In [ ]:
from keras.models import Sequential
model = Sequential()
In [ ]:
from keras.layers import Dense
model.add(Dense(units=6, activation='relu', input_dim=4))
model.add(Dense(units=3, activation='softmax'))
In [ ]:
from keras.utils import plot_model
plot_model(model, show_shapes=True, to_file="model.png")
In [ ]:
model.compile(loss='categorical_crossentropy',
optimizer='sgd',
metrics=['accuracy'])
In [ ]:
iris = datasets.load_iris()
TODO: shuffle
In [ ]:
x_train = iris.data
In [ ]:
y_train = np.zeros(shape=[x_train.shape[0], 3])
In [ ]:
y_train[(iris.target == 0), 0] = 1
y_train[(iris.target == 1), 1] = 1
y_train[(iris.target == 2), 2] = 1
In [ ]:
x_test = x_train
y_test = y_train
In [ ]:
model.fit(x_train, y_train)
In [ ]:
model.evaluate(x_test, y_test)
In [ ]:
model.predict(x_test)