Keras回归模型输出不正确

时间:2019-10-25 17:38:42

标签: python keras

我建立了一个keras回归模型,以使用住房数据及其无法正确输出的方式预测加利福尼亚的住房价格。

可以在[google colabs] [1]上查看完整的代码:

我认为我已经按比例缩放并输入了正确的变量,但是我使用分类问题中的代码进行建模,因此可能不正确。

    sc = StandardScaler()

    X = sc.fit_transform(hous.drop('median_house_value', axis=1))
    y = hous['median_house_value'].values



    from sklearn.model_selection import train_test_split
    X_train, X_test, y_train, y_test = train_test_split(X, y,
                                                    random_state=22,
                                                    test_size=0.2)
    model = Sequential()
    model.add(Dense(32, input_shape=(6,), activation='relu'))
    model.add(Dense(32, activation='relu'))
    model.add(Dense(1, activation='linear'))
    model.compile(Adam(lr=0.05),
              loss='mean_squared_error',
              metrics=['accuracy'])


    model.fit(X_train, y_train, epochs=50, verbose=2,
              validation_split=0.4)


    y_pred = np.log(X_test)

    y_test_class = np.log(y_test, axis=1)
    y_pred_class = np.log(y_pred, axis=1)

结果是:

Epoch 50/50
 - 1s - loss: 5401748800.5233 - accuracy: 0.0000e+00 - val_loss: 5651061434.0796 - val_accuracy: 0.0000e+00
/Users/Avi/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:18: RuntimeWarning: invalid value encountered in log
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-48-4f45ffa7384b> in <module>
     18 y_pred = np.log(X_test)
     19 
---> 20 y_test_class = np.log(y_test, axis=1)
     21 y_pred_class = np.log(y_pred, axis=1)
     22 

TypeError: 'axis' is an invalid keyword to ufunc 'log'"


  [1]: https://drive.google.com/file/d/1dcUuTVVDGwxHn2O5qqJk0wgiEf83MslN/view?usp=sharing

0 个答案:

没有答案