예제 #1
0
              kernel_initializer='uniform',
              activation='relu',
              input_dim=inputnum))
    model.add(
        Dense(units=nodes, kernel_initializer='uniform', activation='relu'))
    model.add(Dense(units=1, kernel_initializer='uniform'))

    # compile the model
    model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mse'])
    return model


# load data files

df_train = load_Training_data(file)
df_test = load_test_data(file)

# filter dataframe by ID
if unit != 0:
    df_train = df_train[df_train['UNIT_ID'] == unit]
    df_test = df_test[df_test['UNIT_ID'] == unit]
    print('result filtered for ID', unit)

# create the training and testing sets from the dataframes
training_set = df_train.iloc[:, 2:].values
test_set = df_test.iloc[:, 2:].values

# scaling
scaler = MinMaxScaler((-1, 1))
training_scaled = scaler.fit_transform(training_set)
test_scaled = scaler.transform(test_set)
예제 #2
0
# Compiling the RNN
regressor.compile(optimizer='adam', loss='mean_squared_error', metrics=['mse'])
es = EarlyStopping(monitor='val_loss', min_delta=0, patience=2, verbose=1)

# Fitting the LSTM to the Training set
start = time.time()
regressor.fit(X_train,
              y_train,
              epochs=99,
              batch_size=32,
              callbacks=[es],
              validation_split=0.2)
end = time.time()

#loading the test data
dataset_test = load_test_data(file)

# filter dataset by ID
if unit != 0:
    dataset_test = dataset_test[dataset_test['UNIT_ID'] == unit]

# select feature from the dataframe
test_set = dataset_test.iloc[:, 2:].values

# scale the test data
test_sc = MinMaxScaler(feature_range=(-1, 1))
inputs = test_sc.fit_transform(test_set)

# scale for the predicted values
sc_predict = MinMaxScaler(feature_range=(-1, 1))
sc_predict.fit_transform(test_set[:, 24:25])