0
我使用Keras做的預測。我訓練它使用數字,Y1和Y2的兩個數組每個輸入數量X.Keras:輸出陣列被弄亂了
我希望得到一個_y1和_Y2的預測,但我不知道怎麼辦。
可視化顯示什麼。這就說得通了。檢查它,它看起來像「predicition」數組爲空。
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)