【发布时间】:2017-12-04 08:45:06
【问题描述】:
我是神经网络的新手(只是免责声明)。
我有一个基于 8 个特征预测混凝土强度的回归问题。我首先做的是使用 min-max 归一化重新调整数据:
# Normalize data between 0 and 1
from sklearn.preprocessing import MinMaxScaler
min_max = MinMaxScaler()
dataframe2 = pd.DataFrame(min_max.fit_transform(dataframe), columns = dataframe.columns)
然后将数据帧转换为 numpy 数组并将其拆分为 X_train、y_train、X_test、y_test。 现在这里是网络本身的 Keras 代码:
from keras.models import Sequential
from keras.layers import Dense, Activation
#Set the params of the Neural Network
batch_size = 64
num_of_epochs = 40
hidden_layer_size = 256
model = Sequential()
model.add(Dense(hidden_layer_size, input_shape=(8, )))
model.add(Activation('relu'))
model.add(Dense(hidden_layer_size))
model.add(Activation('relu'))
model.add(Dense(hidden_layer_size))
model.add(Activation('relu'))
model.add(Dense(1))
model.add(Activation('linear'))
model.compile(loss='mean_squared_error', # using the mean squared error function
optimizer='adam', # using the Adam optimiser
metrics=['mae', 'mse']) # reporting the accuracy with mean absolute error and mean squared error
model.fit(X_train, y_train, # Train the model using the training set...
batch_size=batch_size, epochs=num_of_epochs,
verbose=0, validation_split=0.1)
# All predictions in one array
predictions = model.predict(X_test)
问题:
predictions 数组将包含缩放格式的所有值(介于 0 和 1 之间),但显然我需要预测为真实值。如何将这些输出重新调整为实际值?
Min-Max 还是 Z-Score 标准化更适合回归问题?这个“批量标准化”怎么样?
谢谢,
【问题讨论】:
-
你的问题有点太宽泛了:它包含2个问题,第一个(重新缩放)与keras无关。
-
您的第一个问题已得到解答,第二个问题超出了 stackoverflow 的范围。请查看stats.stackexchange.com
标签: numpy machine-learning scikit-learn keras normalization