CNN模型可为训练提供90%的准确性,但预测输出与训练数据上的要求输出不匹配

时间:2019-06-09 13:25:54

标签: keras

1d cnn模型的预测输出与所需输出不匹配。我给出了6个特征作为输入,输出的大小为5,对于给定的输入特征组合,y的值

    indata=np.loadtxt("hkh") 
    x=indata[:,0:6]
    y=indata[:,6:11]
    print(np.shape(x))
    scaler = MinMaxScaler()
    X_train, X_test, y_train, y_test=sk.model_selection.train_test_split(x,                 y,test_size=0.10)
    min_max_scaler = preprocessing.MinMaxScaler()
    X_train = min_max_scaler.fit_transform(X_train)
    X_test=min_max_scaler.fit_transform(X_test)
    model = Sequential()
    model.add(Conv1D(filters=15, kernel_size=2, activation='relu', input_shape=(X_train.shape[1],1)))
    model.add(Conv1D(filters=15, kernel_size=2, activation='relu'))
    model.add(Dropout(0.5))
    model.add(MaxPooling1D(pool_size=2))
    model.add(Flatten())
    model.add(Dense(50, activation='relu'))
    model.add(Dense(5, activation='linear'))
    model.compile(loss='mean_absolute_error', optimizer='adam', metrics=['accuracy'])
    X_train = np.reshape(X_train, (X_train.shape[0],X_train.shape[1],1))
    X_test = np.reshape(X_test,(X_test.shape[0],X_test.shape[1],1))
    history = model.fit(X_train,y_train, epochs=50, 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("y=%s, Predicted=%s" % (y_train[i], predic[i]))
        sp = model.evaluate(X_train,y_train)
        newpri = model.predict(X_test)
        print("for x test")
        for i in range(len(X_test)):
            print("ytest=%s, Predicted=%s" % (y_test[i], newpri[i]))

这是必需的预测输出的样本。准确性为90%,但没有一个值匹配

      y=[3.10805222e-02 2.24436418e-01 5.06168639e+00 9.14517291e-01       4.69942665e-05], Predicted=[3.2721296e-02 1.4265041e-01 3.8653829e+00     1.4670816e-01 3.5805181e-03]
      y=[1.43702687e+00 1.02620929e+01 2.94557411e+01 6.38936067e+01
      3.16912050e-03], Predicted=[ 0.4163519   0.41520917 12.395155    2.141461    0.01403143]
      y=[6.67620092e-02 1.12757949e-01 2.88987718e+00 4.83045553e-01
       1.17749207e-04], Predicted=[5.4432884e-02 1.5650816e-01     3.7282872e+00    4.6139470e-01 2.9444080e-03]
      y=[3.10786328e-02 2.24434620e-01 5.06222044e+00 9.14579621e-01
      4.69789329e-05], Predicted=[3.2721326e-02 1.4265053e-01 3.8653829e+00    1.4670840e-01 3.5805032e-03]
      y=[6.69400670e-02 1.61406707e-01 3.17028632e+00 7.32215931e-01
      1.18432443e-04], Predicted=[5.6962773e-02 1.7139833e-01 3.7756131e+00 5.2015817e-01 2.9664263e-03]
      y=[6.91875956e-02 3.65085549e-01 2.74661716e+00 2.04664461e+00
      1.21145003e-04], Predicted=[5.2793458e-02 3.7689355e-01 6.2776384e+00  1.6584197e+00 2.4618208e-03]
      y=[3.10805251e-02 2.24436417e-01 5.06168640e+00 9.14517291e-01
      4.69942662e-05], Predicted=[3.2721326e-02 1.4265035e-01 3.8653827e+00 1.4670792e-01 3.5805106e-03]
      y=[3.10805225e-02 2.24436418e-01 5.06168639e+00 9.14517291e-01
      4.69942666e-05], Predicted=[3.2721326e-02 1.4265047e-01 3.8653834e+00 1.4670828e-01 3.5805106e-03]
      y=[5.64502719e-02 5.71580530e+00 1.99965010e+01 3.36289338e+01
      1.50247608e-04], Predicted=[1.0487898e-01 1.0755225e+00 1.0574753e+01 7.5264950e+00 8.0008060e-04]
      y=[2.81795254e-02 7.54185870e-01 7.57469889e+00 3.86340924e+00
 4.58721884e-05], Predicted=[5.3089529e-02 6.6210884e-01 8.0549078e+00 3.3571153e+00 2.5225338e-04]
      y=[9.19760903e-01 5.04343396e-01 5.90905076e+00 3.21928868e+00
 1.84881433e-03], Predicted=[ 0.6721113  -2.6017604   8.049854    0.2546801   0.01589126]
      y=[6.68278637e-02 1.11517506e-01 2.88987876e+00 4.76916113e-01
 1.17747694e-04], Predicted=[0.05055889 0.13947867 3.3866012  0.56084347 0.00844622]
      y=[3.10718700e-02 2.24156272e-01 5.06511107e+00 9.13401194e-01
 4.69297137e-05], Predicted=[0.04475798 0.14583509 2.8354754  0.44338506 0.01016996]
      y=[6.49024943e-02 4.45885908e+00 1.75697493e+01 2.69516257e+01
 1.05433405e-04], Predicted=[ 7.7385567e-02  5.8787674e-01  9.3788900e+00  3.0181587e+00
 -2.3611123e-03]

此处y是必需的,给定的输出是

0 个答案:

没有答案