In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.utils import to_categorical
In [45]:
model = Sequential()
model.add(Dense(20, input_shape=(None,4)))
model.add(Dense(10))
model.add(Dense(5))
model.add(Dense(3))
In [46]:
model.compile('adam', loss='mse')
In [5]:
from sklearn import datasets
In [26]:
x, y = datasets.load_iris(return_X_y=True)
In [27]:
X = x.reshape(1, -1, 4)
In [31]:
Y = to_categorical(y).reshape(1, -1, 3)
In [42]:
splt = int(0.7*len(x))
In [43]:
x_train, x_test = X[:, :splt], X[:, splt:]
y_train, y_test = Y[:, :splt], Y[:, splt:]
In [44]:
x_train.shape
Out[44]:
In [58]:
model.fit(x_train, y_train, shuffle=True, epochs=1000, verbose=0)
Out[58]:
In [59]:
loss = model.evaluate(x_test, y_test)
In [60]:
loss
Out[60]: