Rescaling outputs from Keras model to original scale
I'm new to neural networks (just a disclaimer).
I have a regression problem in predicting the strength of concrete based on 8 characteristics. I first did a rescaling of the data using minimal normalization:
# 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)
then converts the dataframe to a numpy array and splits it into X_train, y_train, X_test, y_test. Now, here is the Keras code for the network itself:
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)
Questions:
-
the predictions array will have all values โโin scaled format (0 to 1), but obviously I need the predictions to be in their real values. How can I rescale this output to real values?
-
Is the standard Min-Max or Z-Score policy more appropriate for regression problems? How about this "batch normalization"?
Thank,
+3
source to share
2 answers