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


According to the doc, the class MinMaxScaler

has a method inverse_transform

that does what you want:



inverse_transform (X): Unscale X according to feature_range.

+2


source


For 1 .: Use inverse_transform()

with the same MinMaxScaler that you have the fit_transformed source data:



http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html#sklearn.preprocessing.MinMaxScaler.inverse_transform

+1


source







All Articles