I am using Keras to do a prediction. I train it using two arrays of numbers, Y1 and Y2 for each input number X.
I want to get a prediction of a _Y1 and a _Y2, but I don't know how.
The visualization shows nothing. That makes sense. Checking it, it looks like the "predicition" array is empty.
import numpy as np
import pandas
import math
import random
from keras.models import Sequential, Model
from keras.layers import Input, Dense
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
import graphviz
import pydot
import matplotlib.pyplot as plt
X = np.array([])
Y_int = np.array([])
Y1 = np.array([])
Y2 = np.array([])
count = -1
while count < 1:
count += 0.001
X += np.array([count])
i = ( math.sin(count) )
Y_int += np.array([i])
if i > 1 or i < -1:
o = 1
u = 1 / i
else:
o = i
u = 1
Y1 += np.array([o])
Y2 += np.array([u])
length = len(X)
# define base model
def baseline_model():
# create model
model = Sequential()
inp = Input((1,))
x = Dense(100, kernel_initializer='lecun_normal', activation='tanh')(inp)
out1 = Dense(1, kernel_initializer='lecun_normal')(x)
out2 = Dense(1, kernel_initializer='lecun_normal')(x)
model = Model(inp, [out1,out2])
# Compile model
model.compile(loss='mean_squared_error', optimizer='adam')
return model
estimator = baseline_model();
estimator.fit(X, [Y1, Y2], batch_size = 20, epochs = 1, verbose = 0)
plt.axis([-1, 1, -1, 1])
plt.ion()
while True:
estimator.fit(X, [Y1, Y2], batch_size = 20, epochs = 1, verbose = 0)
prediction = estimator.predict(X)
plt.clf()
plt.plot(X, Y_int)
plt.plot(X, prediction )
plt.pause(0.001)