我想用 Keras 做简单的预测,但我不确定我是否做对了。我的数据如下所示:
col1,col2
1.68,237537
1.69,240104
1.70,244885
1.71,246196
1.72,246527
1.73,254588
1.74,255112
1.75,259035
1.76,267229
1.77,267314
1.78,268931
1.79,273497
1.80,273900
1.81,277132
1.82,278066
现在,我想预测col2,col1这就是我的做法:
df = pandas.read_csv('data.csv', usecols=[0, 1], header=None)
X = df.iloc[:, :-1].values.astype(np.float64)
y = df.iloc[:, -1:].values.astype(np.float64)
scalarX, scalarY = MinMaxScaler(), MinMaxScaler()
标量X.fit(X)
scalarY.fit(y.reshape(len(y),1))
X = 标量X.transform(X)
y = scalarY.transform(y.reshape(len(y),1))
模型=顺序()
model.add(密集(4,input_dim=1,激活='relu'))
model.add(密集(4,激活='relu'))
model.add(密集(1,激活='线性'))
model.compile(损失='mse',优化器='adam')
model.fit(x=X, y=y, epochs=3, 详细=1)
对于范围内的 num(1, 21):
Xnew = np.array([[float(Decimal('2.{}'.format(num)))]])
ynew = model.predict(Xnew)
print("X=%s, 预测=%s" % (Xnew[0], ynew[0]))