我正在尝试使用神经网络来预测房价。这是数据集顶部的样子:
Price Beds SqFt Built Garage FullBaths HalfBaths LotSqFt
485000 3 2336 2004 2 2.0 1.0 2178.0
430000 4 2106 2005 2 2.0 1.0 2178.0
445000 3 1410 1999 1 2.0 0.0 3049.0
...
我正在尝试使用 ReLU 激活函数,但即使在 100 个 epoch 之后我的准确度也为零。我在这里错过了什么吗?
X = dataset[:,1:8] #predictor variables
Y = dataset[:,0] #sell price
#Normalize data
from sklearn import preprocessing
X_scale = min_max_scaler.fit_transform(X)
X_scale
#Split Data
from sklearn.model_selection import train_test_split
X_train, X_val_and_test, Y_train, Y_val_and_test = train_test_split(X_scale, Y, test_size=0.3)
X_val, X_test, Y_val, Y_test = train_test_split(X_val_and_test, Y_val_and_test, test_size=0.5)
print(X_train.shape, X_val.shape, X_test.shape, Y_train.shape, Y_val.shape, Y_test.shape)
- 实施模型
from keras.models import Sequential
from keras.layers import Dense
model = Sequential(
Dense(32, activation='relu', input_shape=(7,)))
model.compile(optimizer='sgd',
loss='binary_crossentropy',
metrics=['accuracy'])
hist = model.fit(X_train, Y_train,
batch_size=32, epochs=100,
validation_data=(X_val, Y_val))
model.evaluate(X_test, Y_test)[1]
## Output: 3/3 [==============================] - 0s 3ms/step - loss: -5698781.5000 - accuracy: 0.0000e+00