I have built an ANN using keras library.


# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train_us, X_test_us, y_train_us, y_test_us = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_Y = StandardScaler()
X_train = sc_X.fit_transform(X_train_us)
X_test = sc_X.transform(X_test_us)
y_train = sc_Y.fit_transform(y_train_us)
y_test = sc_Y.transform(y_test_us)

# Importing the Keras libraries and packages
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasRegressor
#from keras.layers import Dropout

def base_model():
    # Initialising the ANN
    regressor = Sequential()   
    # Adding the input layer and the first hidden layer
    regressor.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))   
    # Adding the second hidden layer
    regressor.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))   
    # Adding the output layer
    regressor.add(Dense(units = 1, kernel_initializer = 'uniform'))
    # Compiling the ANN
    regressor.compile(optimizer = 'adam', loss = 'mse', metrics = ['mae'])
    return regressor

# Fitting the ANN to the Training set
regressor = KerasRegressor(build_fn=base_model, epochs=500, batch_size=32)

After training the model on this data set, I have saved the model as json and weights as .h5 file. I have used this model for a while. Now I have a new set of data available, and wish to train the model using this data set.

So I have loaded the model and its weights. Now when I train the model on the new data, my new data should be scaled using new scalar objects or the previous used scalar objects are to be used? I am confused about this part. Can some one help me understand?

Related posts

Recent Viewed