In [1]:
import keras
In [2]:
import numpy as np
In [3]:
x = np.array(range(100))
In [4]:
x
Out[4]:
In [5]:
y = x * 2 + 1
In [6]:
y
Out[6]:
In [7]:
model = keras.models.Sequential()
In [8]:
model.add(keras.layers.Dense(1, input_shape = (1,)))
In [9]:
model.compile('Adam', 'mse')
In [10]:
model.fit(x, y, epochs=1000, verbose=0)
Out[10]:
In [11]:
x[:2]
Out[11]:
In [12]:
y[:2]
Out[12]:
In [13]:
print('Targets : ', y[2:5])
print('Predictions : ', model.predict(np.array([2,3,4])).flatten())
In [14]:
x.shape
Out[14]:
In [15]:
np.array(4).shape
Out[15]:
In [16]:
np.array([4]).shape
Out[16]:
In [ ]: