我正在尝试构建一个1dconvnet,使其获得90%的训练精度,但是当我对训练数据进行预测时,它给出的输出完全错误。 这是输入的样本,前6列分别是输入和 接下来的5个是必需的输出。
1.00000000e-01 1.63298086e-01 0.00000000e+00 -8.20000000e-01 2.61841700e-03 2.63696445e-06 1.08083579e-01 2.85828080e-01 2.20500852e+02 2.32888782e+00 2.41456262e-04
这是我的代码:
indata=np.loadtxt("hkh")
x=indata[:,0:6]
y=indata[:,6:11]
x_train, x_test, y_train, y_test = sk.model_selection.train_test_split(x, y , train_size = 0.7, random_state = 10)
min_max_scaler = preprocessing.MinMaxScaler()
X_train = min_max_scaler.fit_transform(x_train)
X_test=min_max_scaler.fit_transform(x_test)
X_train = np.reshape(X_train, (X_train.shape[0],X_train.shape[1],1))
model=Sequential()
model.add(Conv1D(filters=15,kernel_size=4,padding='same',
activation='relu',input_shape=(X_train.shape[1],1)))
model.add(Dropout(0.25))
model.add(Conv1D(filters=5, kernel_size=2,padding='same',activation='relu'))
model.add(Dropout(0.25))
model.add(Conv1D(filters=5,kernel_size=2,
padding='same',activation='relu'))
model.add(Flatten())
model.add(Dense(50,activation='relu',kernel_initializer='uniform'))
model.add(Dense(5,activation='linear',kernel_initializer='uniform'))
model.compile(loss='mean_absolute_error', optimizer ='adam', metrics= ['mae','accuracy'])
history=model.fit(X_train,y_train, epochs=200, batch_size=10,validation_split=0.1,verbose=1)
scores = model.evaluate(X_train,y_train)
predic=model.predict(X_train)
for i in range(len(y_train)):
print("x=%s,y=%s, Predicted=%s" % (X_train[i],y_train[i], predic[i]))
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]))
print("\n%s: %.2f%%" % (model.metrics_names[2], scores[2]*100))
这是我得到的输出示例:
x=[[0.2501796 ]
[0.44190583]
[0.527626 ]
[0.19207867]
[0.53887458]
[0.49529559]],y=[6.77109904e-02 3.82207159e-01 2.65739091e+00 2.11313069e+00,1.21107806e-04], Predicted=[4.6628892e-02 3.2888740e-01 6.4958944e+00 1.5410656e+00 3.8460200e-03]
x=[[0.83208 ]
[0.69995424]
[1. ]
[0.5655 ]
[0.15205588]
[0.05734445]],y=[2.91771194e-02 7.57368989e+00 2.94492555e+01 3.99317746e+01 4.17960309e-05], Predicted=[5.4871000e-02 4.5698667e-01 8.3479452e+00 2.3280945e+00 3.9289482e-03]
x=[[0.2396676 ]
[0.43449596]
[0.54114267]
[0.17252033]
[0.54459136]
[0.50007482]],y=[9.90796380e-02 1.88558781e-01 4.22531358e+00 9.17130688e-01,1.77772516e-04], Predicted=[4.5275073e-02 3.0784631e-01 6.1916838e+00 1.4117914e+00 3.8323984e-03]
mean_absolute_error: 5.92%
acc: 90.14%