def main(argv):
    """ Predict based on the trained model and specfic checkpoints. """
    assert len(argv) == 1
    (x_train_dev, y_train_dev), (x_train0, y_train0), (x_dev0, y_dev0), (
        x_test0, y_test0), (series_max,
                            series_min) = load_normalized_data('VMD_IMFS.xlsx',
                                                               seed=123)
    # data_file = 'ARMA_IMFs_PRED.xlsx'
    # data_file = 'SVR_IMFs_PRED.xlsx'
    # data_file = 'GBR_IMFs_PRED.xlsx'
    data_file = 'DNN_IMFs_PRED.xlsx'
    # print(10 * '-' + ' Data file: {}'.format(data_file))
    # # laod data from local disk.
    # (x_train_dev, y_train_dev), (x_train, y_train), (x_dev, y_dev), (
    #     x_test, y_test), (series_max,
    #                       series_min) = load_normalized_data(
    #                           data_file, seed=123)

    full_data_set = pd.read_excel(par_path_2 + '\\data\\' + data_file)
    full_norm_set = 2 * (full_data_set - series_min) / (series_max -
                                                        series_min) - 1
    series_len = len(full_norm_set)
    train_dev_set = full_norm_set[0:(series_len - 541)]
    y_train_dev = train_dev_set['Y']
    x_train_dev = train_dev_set.drop('Y', axis=1)
    # Get the test set
    test_set = full_norm_set[(series_len - 541):series_len]
    # Shuffle the data
    np.random.seed(123)
    # split the data into train/developing subsets
    x_train = train_dev_set.sample(frac=0.888888889, random_state=123)
    x_dev = train_dev_set.drop(x_train.index)
    # Extract the label from the features dataframe
    y_train = x_train.pop('Y')
    y_dev = x_dev.pop('Y')
    # print(test_set)
    x_test = test_set
    y_test = x_test.pop('Y')

    # create feature colums
    feature_columns = [
        tf.feature_column.numeric_column("X1"),
        tf.feature_column.numeric_column("X2"),
        tf.feature_column.numeric_column("X3"),
        tf.feature_column.numeric_column("X4"),
        tf.feature_column.numeric_column("X5"),
        tf.feature_column.numeric_column("X6"),
        tf.feature_column.numeric_column("X7"),
        tf.feature_column.numeric_column("X8"),
        tf.feature_column.numeric_column("X9"),
        tf.feature_column.numeric_column("X10"),
    ]

    # recovery the model, and set the dropout rate to 0.0
    model_path = current_path + '/models/ensemble/'
    current_model = 'DNNRegressor_Hidden_Units[9, 8]'
    model_dir = model_path + current_model + '/'

    # model = tf.estimator.Estimator(
    #     model_fn=my_dnn_regression_fn,
    #     model_dir=model_dir,
    #     params={
    #         'feature_columns': feature_columns,
    #         # NOTE: Set the hidden units for predictions
    #         'hidden_units': [7],
    #         'drop_rates': [0.0]
    #     },
    # )

    model = tf.estimator.DNNRegressor(
        hidden_units=[9, 8],
        feature_columns=feature_columns,
        model_dir=model_dir,
    )

    train_pred_input_fn = tf.estimator.inputs.pandas_input_fn(x_train,
                                                              shuffle=False)
    dev_pred_input_fn = tf.estimator.inputs.pandas_input_fn(x_dev,
                                                            shuffle=False)
    test_pred_input_fn = tf.estimator.inputs.pandas_input_fn(x_test,
                                                             shuffle=False)

    # Use the specific file to predict
    checkpoint_path = model_dir + 'model.ckpt-22400'

    # predict the training set by specfic checkpoint
    train_pred_results = model.predict(input_fn=train_pred_input_fn,
                                       checkpoint_path=checkpoint_path)
    # predict the developing set
    dev_pred_results = model.predict(input_fn=dev_pred_input_fn,
                                     checkpoint_path=checkpoint_path)
    # predict the testing set.
    test_pred_results = model.predict(input_fn=test_pred_input_fn,
                                      checkpoint_path=checkpoint_path)

    # Convert generator to numpy array
    train_predictions = np.array(
        list(p['predictions'] for p in train_pred_results))
    dev_predictions = np.array(list(p['predictions']
                                    for p in dev_pred_results))
    test_predictions = np.array(
        list(p['predictions'] for p in test_pred_results))

    # reshape the prediction to y shape.
    train_predictions = train_predictions.reshape(np.array(y_train).shape)
    dev_predictions = dev_predictions.reshape(np.array(y_dev).shape)
    test_predictions = test_predictions.reshape(np.array(y_test).shape)

    # Renormalize the records and predictions
    y_train = np.multiply(
        y_train + 1, series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
    train_predictions = np.multiply(train_predictions + 1, series_max["Y"] -
                                    series_min["Y"]) / 2 + series_min["Y"]
    y_dev = np.multiply(
        y_dev + 1, series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
    dev_predictions = np.multiply(dev_predictions + 1, series_max["Y"] -
                                  series_min["Y"]) / 2 + series_min["Y"]
    y_test = np.multiply(
        y_test + 1, series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
    test_predictions = np.multiply(test_predictions + 1, series_max["Y"] -
                                   series_min["Y"]) / 2 + series_min["Y"]

    # compute R square
    r2_train = r2_score(y_train, train_predictions)
    r2_dev = r2_score(y_dev, dev_predictions)
    r2_test = r2_score(y_test, test_predictions)

    # compute MSE
    mse_train = mean_squared_error(y_train, train_predictions)
    mse_dev = mean_squared_error(y_dev, dev_predictions)
    mse_test = mean_squared_error(y_test, test_predictions)

    # compute MAE
    mae_train = mean_absolute_error(y_train, train_predictions)
    mae_dev = mean_absolute_error(y_dev, dev_predictions)
    mae_test = mean_absolute_error(y_test, test_predictions)

    # compute MAPE
    mape_train = np.true_divide(
        np.sum(np.abs(np.true_divide(
            (y_train - train_predictions), y_train))), y_train.size) * 100
    mape_dev = np.true_divide(
        np.sum(np.abs(np.true_divide(
            (y_dev - dev_predictions), y_dev))), y_dev.size) * 100
    mape_test = np.true_divide(
        np.sum(np.abs(np.true_divide(
            (y_test - test_predictions), y_test))), y_test.size) * 100

    #
    print('r2_score_train = {:.10f}'.format(r2_train))
    print('r2_score_dev = {:.10f}'.format(r2_dev))

    dump_train_dev_test_to_excel(path=model_path + current_model + data_file +
                                 '.xlsx',
                                 y_train=y_train,
                                 train_pred=train_predictions,
                                 r2_train=r2_train,
                                 mse_train=mse_train,
                                 mae_train=mae_train,
                                 mape_train=mape_train,
                                 y_dev=y_dev,
                                 dev_pred=dev_predictions,
                                 r2_dev=r2_dev,
                                 mse_dev=mse_dev,
                                 mae_dev=mae_dev,
                                 mape_dev=mape_dev,
                                 y_test=y_test,
                                 test_pred=test_predictions,
                                 r2_test=r2_test,
                                 mse_test=mse_test,
                                 mae_test=mae_test,
                                 mape_test=mape_test)

    plot_rela_pred(y_train,
                   train_predictions,
                   series_max,
                   series_min,
                   fig_savepath=model_path + current_model + data_file +
                   '_train_pred.tif')

    plot_rela_pred(y_dev,
                   dev_predictions,
                   series_max,
                   series_min,
                   fig_savepath=model_path + current_model + data_file +
                   "_dev_pred.tif")

    plot_rela_pred(y_test,
                   test_predictions,
                   series_max,
                   series_min,
                   fig_savepath=model_path + current_model + data_file +
                   "_test_pred.tif")
Пример #2
0
def main(argv):
    """ Predict based on the trained model and specfic checkpoints. """
    assert len(argv) == 1

    # laod data from local disk.
    (x_train_dev, y_train_dev), (x_train, y_train), (x_dev, y_dev), (
        x_test, y_test), (series_max, series_min) = load_normalized_data(
            # "orig_day_full_X.xlsx", # Do original prediction
            "vmd_imf10.xlsx", # Do vmd IMFs prediction
             seed=123)

    # create feature colums
    feature_columns = [
        tf.feature_column.numeric_column("X1"),
        tf.feature_column.numeric_column("X2"),
        tf.feature_column.numeric_column("X3"),
        # tf.feature_column.numeric_column("X4"),
        # tf.feature_column.numeric_column("X5"),
        # tf.feature_column.numeric_column("X6"),
        # tf.feature_column.numeric_column("X7"),
        # tf.feature_column.numeric_column("X8"),
        # tf.feature_column.numeric_column("X9"),
        # tf.feature_column.numeric_column("X10"),
        # tf.feature_column.numeric_column("X11"),
        # tf.feature_column.numeric_column("X12"),
        # tf.feature_column.numeric_column("X13"),
        # tf.feature_column.numeric_column("X14"),
        # tf.feature_column.numeric_column("X15"),
        # tf.feature_column.numeric_column("X16"),
        # tf.feature_column.numeric_column("X17"),
        # tf.feature_column.numeric_column("X18"),
        # tf.feature_column.numeric_column("X19"),
    ]

    # recovery the model, and set the dropout rate to 0.0
    model_path = current_path + '/models/imf10/'

    # current_model = 'DNNRegressor_Hidden_Units[7, 13]'  # orig
    # current_model = 'DNNRegressor_Hidden_Units[5, 8]'  # imf1
    # current_model = 'DNNRegressor_Hidden_Units[3]'  # imf2
    # current_model = 'DNNRegressor_Hidden_Units[9, 12]'  # imf3
    # current_model = 'DNNRegressor_Hidden_Units[6, 10]'  # imf4
    # current_model = 'DNNRegressor_Hidden_Units[5, 11]'  # imf5
    # current_model = 'DNNRegressor_Hidden_Units[4, 7]'  # imf6
    # current_model = 'DNNRegressor_Hidden_Units[11, 12]'  # imf7
    # current_model = 'DNNRegressor_Hidden_Units[4]'  # imf8
    # current_model = 'DNNRegressor_Hidden_Units[13, 12]'  # imf9
    current_model = 'DNNRegressor_Hidden_Units[3]'  # imf10
    model_dir = model_path + current_model + '/'

    # model = tf.estimator.Estimator(
    #     model_fn=my_dnn_regression_fn,
    #     model_dir=model_dir,
    #     params={
    #         'feature_columns': feature_columns,
    #         # NOTE: Set the hidden units for predictions
    #         'hidden_units': [7],
    #         'drop_rates': [0.0]
    #     },
    # )

    model = tf.estimator.DNNRegressor(
        # hidden_units=[7, 13], # orig
        # hidden_units=[5, 8], # imf1
        # hidden_units=[3], # imf2
        # hidden_units=[9,12], # imf3
        # hidden_units=[6,10], # imf4
        # hidden_units=[5,11], # imf5
        # hidden_units=[4], # imf6
        # hidden_units=[11,12], # imf7
        # hidden_units=[13,12], # imf9
        hidden_units=[3], # imf10
        feature_columns=feature_columns,
        model_dir=model_dir,
    )

    train_pred_input_fn = tf.estimator.inputs.pandas_input_fn(
        x_train, shuffle=False)
    dev_pred_input_fn = tf.estimator.inputs.pandas_input_fn(
        x_dev, shuffle=False)
    test_pred_input_fn = tf.estimator.inputs.pandas_input_fn(
        x_test, shuffle=False)

    # Use the specific file to predict
    # checkpoint_path = model_dir + 'model.ckpt-7200' #orig
    # checkpoint_path = model_dir + 'model.ckpt-29600' #imf1
    # checkpoint_path = model_dir + 'model.ckpt-50600' #imf2
    # checkpoint_path = model_dir + 'model.ckpt-74900' #imf3
    # checkpoint_path = model_dir + 'model.ckpt-30000' #imf4
    # checkpoint_path = model_dir + 'model.ckpt-73100' #imf5
    # checkpoint_path = model_dir + 'model.ckpt-81700' #imf6
    # checkpoint_path = model_dir + 'model.ckpt-13200' #imf7
    # checkpoint_path = model_dir + 'model.ckpt-32800' #imf8
    # checkpoint_path = model_dir + 'model.ckpt-11700' #imf9
    checkpoint_path = model_dir + 'model.ckpt-45600' #imf10

    # predict the training set by specfic checkpoint
    train_pred_results = model.predict(
        input_fn=train_pred_input_fn, checkpoint_path=checkpoint_path)
    # predict the developing set
    dev_pred_results = model.predict(
        input_fn=dev_pred_input_fn, checkpoint_path=checkpoint_path)
    # predict the testing set.
    test_pred_results = model.predict(
        input_fn=test_pred_input_fn, checkpoint_path=checkpoint_path)

    # Convert generator to numpy array
    train_predictions = np.array(
        list(p['predictions'] for p in train_pred_results))
    dev_predictions = np.array(
        list(p['predictions'] for p in dev_pred_results))
    test_predictions = np.array(
        list(p['predictions'] for p in test_pred_results))

    # reshape the prediction to y shape.
    train_predictions = train_predictions.reshape(np.array(y_train).shape)
    dev_predictions = dev_predictions.reshape(np.array(y_dev).shape)
    test_predictions = test_predictions.reshape(np.array(y_test).shape)

    # Renormalize the records and predictions
    y_train = np.multiply(
        y_train + 1, series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
    train_predictions = np.multiply(train_predictions + 1, series_max["Y"] -
                                    series_min["Y"]) / 2 + series_min["Y"]
    y_dev = np.multiply(
        y_dev + 1, series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
    dev_predictions = np.multiply(dev_predictions + 1, series_max["Y"] -
                                  series_min["Y"]) / 2 + series_min["Y"]
    y_test = np.multiply(
        y_test + 1, series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
    test_predictions = np.multiply(test_predictions + 1, series_max["Y"] -
                                   series_min["Y"]) / 2 + series_min["Y"]

    # compute R square
    r2_train = r2_score(y_train, train_predictions)
    r2_dev = r2_score(y_dev, dev_predictions)
    r2_test = r2_score(y_test, test_predictions)

    # compute MSE
    mse_train = mean_squared_error(y_train, train_predictions)
    mse_dev = mean_squared_error(y_dev, dev_predictions)
    mse_test = mean_squared_error(y_test, test_predictions)

    # compute MAE
    mae_train = mean_absolute_error(y_train, train_predictions)
    mae_dev = mean_absolute_error(y_dev, dev_predictions)
    mae_test = mean_absolute_error(y_test, test_predictions)

    # compute MAPE
    mape_train = np.true_divide(
        np.sum(np.abs(np.true_divide(
            (y_train - train_predictions), y_train))), y_train.size) * 100
    mape_dev = np.true_divide(
        np.sum(np.abs(np.true_divide(
            (y_dev - dev_predictions), y_dev))), y_dev.size) * 100
    mape_test = np.true_divide(
        np.sum(np.abs(np.true_divide(
            (y_test - test_predictions), y_test))), y_test.size) * 100

    #
    print('r2_score_train = {:.10f}'.format(r2_train))
    print('r2_score_dev = {:.10f}'.format(r2_dev))

    dump_train_dev_test_to_excel(
        path=model_path + current_model + '.xlsx',
        y_train=y_train,
        train_pred=train_predictions,
        r2_train=r2_train,
        mse_train=mse_train,
        mae_train=mae_train,
        mape_train=mape_train,
        y_dev=y_dev,
        dev_pred=dev_predictions,
        r2_dev=r2_dev,
        mse_dev=mse_dev,
        mae_dev=mae_dev,
        mape_dev=mape_dev,
        y_test=y_test,
        test_pred=test_predictions,
        r2_test=r2_test,
        mse_test=mse_test,
        mae_test=mae_test,
        mape_test=mape_test)

    plot_rela_pred(
        y_train,
        train_predictions,
        series_max,
        series_min,
        fig_savepath=model_path + current_model + '_train_pred.tif')

    plot_rela_pred(
        y_dev,
        dev_predictions,
        series_max,
        series_min,
        fig_savepath=model_path + current_model + "_dev_pred.tif")

    plot_rela_pred(
        y_test,
        test_predictions,
        series_max,
        series_min,
        fig_savepath=model_path + current_model + "_test_pred.tif")
import numpy as np
import matplotlib.pyplot as plt

from sklearn.svm import SVR, NuSVR
from sklearn.model_selection import cross_val_score
from skopt.space import Real, Integer
from skopt.utils import use_named_args
from skopt import gp_minimize
from skopt.plots import plot_convergence

from load_data import load_normalized_data

if __name__ == '__main__':
    (x_train_dev, y_train_dev), (x_train, y_train), (x_dev, y_dev), (
        x_test, y_test), (series_max,
                          series_min) = load_normalized_data("vmd_imf4.xlsx")

    reg = SVR(tol=1e-8)

    space = [
        Real(0.1, 25, name='C'),
        Real(10**-10, 10**0, name='epsilon'),
        Real(10**-10, 10**0, name='gamma'),
    ]

    @use_named_args(space)
    def objective(**params):
        reg.set_params(**params)
        return -np.mean(
            cross_val_score(reg,
                            x_train_dev,
Пример #4
0
print(10 * '-' + ' Parent Path: {}'.format(par_path_1))
print(10 * '-' + ' Grandpa Path: {}'.format(par_path_2))
sys.path.append(par_path_1 + '\\test\\')
from dump_data import dump_train_dev_test_to_excel

if __name__ == '__main__':

    model_path = current_path + '\\models\\imf10\\'
    data_file = 'vmd_imf10.xlsx'
    print(10 * '-' + ' model path: {}'.format(model_path))
    print(10 * '-' + ' data file: {}'.format(data_file))
    # load data
    (x_train_dev, y_train_dev), (x_train, y_train), (x_dev, y_dev), (
        x_test, y_test), (series_max, series_min) = load_normalized_data(
            # "orig_day_full_X.xlsx",
            #  "vmd_imf4.xlsx",
            data_file,
            seed=123)
    """ # Hyper-params for Original
    reg = SVR(
        C=1.68926756, epsilon=0.00002334, gamma=0.93010959)  #Best Score=0.0036 """
    """ # Hyper-params for IMF1
    reg = SVR(
        C=23.96795408, epsilon=0.00000141,
        gamma=0.33998293)  #Best Score=0.0007 """
    """ # Hyper-params for IMF2
    reg = SVR(
        C=23.96795408, epsilon=0.00000141,
        gamma=0.33998293)  #Best Score=0.0010 """
    """ # Hyper-params for IMF3
    reg = SVR(
Пример #5
0
import sys
sys.path.append(par_path_1 + '\\test\\')
from dump_data import dump_train_dev_test_to_excel

if __name__ == '__main__':

    model_path = current_path + '\\models\\imf10\\'
    # data_file = 'orig_day_full_X.xlsx'
    data_file = 'vmd_imf10.xlsx'
    print(10 * '-' + ' model path: {}'.format(model_path))
    print(10 * '-' + ' data file: {}'.format(data_file))

    # load data
    (x_train_dev, y_train_dev), (x_train, y_train), (x_dev, y_dev), (
        x_test, y_test), (series_max,
                          series_min) = load_normalized_data(data_file,
                                                             seed=123)
    """ # Hyperparameters for orig
    GBR = GradientBoostingRegressor(
        learning_rate=0.564013,
        max_depth=1,
        max_features=6,
        min_samples_split=199,
        min_samples_leaf=8) """
    """ # Hyperparameters for vmd_imf1
    GBR = GradientBoostingRegressor(
        learning_rate=0.268431,
        max_depth=10,
        max_features=3,
        min_samples_split=100,
        min_samples_leaf=1
        ) """
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import cross_val_score
from skopt.space import Real, Integer
from skopt.utils import use_named_args
from skopt import gp_minimize
from skopt.plots import plot_convergence

# import data
from load_data import load_normalized_data

if __name__ == '__main__':
    # load data
    (x_train_dev, y_train_dev), (x_train, y_train), (x_dev, y_dev), (
        x_test, y_test), (series_max,
                          series_min) = load_normalized_data("VMD_IMFS.xlsx")

    # Get the feature num
    n_features = x_train_dev.shape[1]

    reg = GradientBoostingRegressor(n_estimators=50, random_state=0)

    # The list hyper-parameters we want
    space = [
        Integer(1, 25, name='max_depth'),
        Real(10**-5, 10**0, 'log-uniform', name='learning_rate'),
        # Integer(1,n_features,name='max_features'),
        Integer(2, 100, name='min_samples_split'),
        Integer(1, 100, name='min_samples_leaf'),
    ]
def main(argv):
    """ Builds, Trians, and evaluates the model. """
    assert len(argv) == 1

    # laod data from local disk.
    (x_train_dev, y_train_dev), (x_train, y_train), (x_dev, y_dev), (
        x_test, y_test), (series_max,
                          series_min) = load_normalized_data("vmd_imf1.xlsx")

    # Build the training input_fn
    def input_train(features=x_train, labels=y_train, batch_size=256):
        """ An input function for training """
        # convert the input to a Dataset
        dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels))

        # Shffling with a buffer larger than the data set ensures
        # that the examples are will mixed.
        dataset = dataset.shuffle(4000).batch(
            batch_size).repeat().make_one_shot_iterator().get_next()

        return dataset

    # Build the validation input_fn
    def input_dev(features=x_dev, labels=y_dev, batch_size=256):
        # Convert the input to a Dataset
        dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels))

        # Shuffling
        dataset = dataset.shuffle(2000).batch(
            batch_size).make_one_shot_iterator().get_next()

        return dataset

    feature_columns = [
        tf.feature_column.numeric_column("X1"),
        tf.feature_column.numeric_column("X2"),
        tf.feature_column.numeric_column("X3"),
        # tf.feature_column.numeric_column("X4"),
        # tf.feature_column.numeric_column("X5"),
        # tf.feature_column.numeric_column("X6"),
        # tf.feature_column.numeric_column("X7"),
        # tf.feature_column.numeric_column("X8"),
        # tf.feature_column.numeric_column("X9"),
        # tf.feature_column.numeric_column("X10"),
        # tf.feature_column.numeric_column("X11"),
        # tf.feature_column.numeric_column("X12"),
        # tf.feature_column.numeric_column("X13"),
        # tf.feature_column.numeric_column("X14"),
        # tf.feature_column.numeric_column("X15"),
        # tf.feature_column.numeric_column("X16"),
        # tf.feature_column.numeric_column("X17"),
        # tf.feature_column.numeric_column("X18"),
        # tf.feature_column.numeric_column("X19"),
    ]

    my_check_point_config = tf.estimator.RunConfig(
        save_checkpoints_steps=50,
        keep_checkpoint_max=1000  #Retain the 50most recent checkpoints
    )

    for learning_rate in [0.01]:
        decay_steps = 1000  # Learning rate decay steps
        decay_rate = 0.98  # Learning rate decay rate
        hidden_units = [5, 5]  #5:14
        batch_size = 256
        drop_rates = [0.0]
        # construct a hyperparameter str
        hparam_str = 'lr' + str(learning_rate) + '_ds' + str(
            decay_steps) + '_dr' + str(decay_rate) + '_hu' + str(
                hidden_units) + '_bs' + str(batch_size) + '_drop' + str(
                    drop_rates)

        model_dir = model_path + hparam_str

        # Build a custom Estimator, using the model_fn
        # 'params' is passed through the 'model_fn'
        model = tf.estimator.Estimator(
            model_fn=my_dnn_regression_fn,
            model_dir=model_dir,
            params={
                'feature_columns': feature_columns,
                'learning_rate': learning_rate,
                # without learning_rate decay
                'decay_steps': decay_steps,
                'decay_rate': decay_rate,
                'optimizer': tf.train.AdamOptimizer,
                'hidden_units': hidden_units,
                'drop_rates': drop_rates
            },
            config=my_check_point_config)
        """ fig = plt.figure(figsize=(16,9))
        ax221 = plt.subplot(2,2,1)
        ax221.set_title('train predict line')
        ax221.set_xlabel('Time(day)')
        ax221.set_ylabel('flow(' + r'$m^3$' + '/s)')
        ax221.grid()
        ax222 = plt.subplot(2, 2, 2)
        ax222.set_title('train predictions and records scatters')
        ax222.set_xlabel('predictions(' + r'$m^3$' + '/s)')
        ax222.set_ylabel('records(' + r'$m^3$' + '/s)')
        ax222.grid()
        ax223 = plt.subplot(2, 2, 3)
        ax223.set_title('develop predict line')
        ax223.set_xlabel('Time(day)')
        ax223.set_ylabel('flow(' + r'$m^3$' + '/s)')
        ax223.grid()
        ax224 = plt.subplot(2, 2, 4)
        ax224.set_title('develop predictions and records scatters')
        ax224.set_xlabel('predictions(' + r'$m^3$' + '/s)')
        ax224.set_ylabel('records(' + r'$m^3$' + '/s)')
        ax224.grid() """

        for i in range(20):
            # Train the model
            model.train(input_fn=input_train, steps=STEPS)

            # Evaluate how the model performs on a data it has not yet seen.
            eval_result = model.evaluate(input_fn=input_dev, steps=STEPS)

            # The evaluation returns a python dictionary. The 'average loss' key is
            # hold the Mean Square Error (MSE)
            average_loss = eval_result['mse']
            # Convert MSE to root mean square error (RMSE)
            print("\n" + 80 * "*")
            print("\nRMS error for the validation set: {:.8f}".format(
                average_loss))
            print()

            train_pred_input_fn = tf.estimator.inputs.pandas_input_fn(
                x_train, shuffle=False)
            dev_pred_input_fn = tf.estimator.inputs.pandas_input_fn(
                x_dev, shuffle=False)

            # predict the training set
            train_pred_results = model.predict(input_fn=train_pred_input_fn)
            # predict the testing set
            dev_pred_results = model.predict(input_fn=dev_pred_input_fn)

            # Convert generator to numpy array
            train_predictions = np.array(
                list(p['predictions'] for p in train_pred_results))
            dev_predictions = np.array(
                list(p['predictions'] for p in dev_pred_results))
            train_predictions = train_predictions.reshape(
                np.array(y_train).shape)
            dev_predictions = dev_predictions.reshape(np.array(y_dev).shape)

            # Renormalize the records and predictions
            # y_train = np.multiply(y_train,series_max["Y"] - series_min["Y"]) + series_mean["Y"]
            y_train = np.multiply(y_train + 1, series_max["Y"] -
                                  series_min["Y"]) / 2 + series_min["Y"]
            # train_predictions = np.multiply(train_predictions, series_max["Y"] -series_min["Y"]) + series_mean["Y"]
            train_predictions = np.multiply(
                train_predictions + 1,
                series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
            # y_dev = np.multiply(y_dev,series_max["Y"] - series_min["Y"]) + series_mean["Y"]
            y_dev = np.multiply(y_dev + 1, series_max["Y"] -
                                series_min["Y"]) / 2 + series_min["Y"]
            # dev_predictions = np.multiply(dev_predictions, series_max["Y"] - series_min["Y"]) + series_mean["Y"]
            dev_predictions = np.multiply(
                dev_predictions + 1,
                series_max["Y"] - series_min["Y"]) / 2 + series_min["Y"]
            # y_test = np.multiply(y_test,series_max["Y"] - series_min["Y"]) + series_mean["Y"]
            # test_predictions = np.multiply(test_predictions, series_max["Y"] - series_min["Y"]) + series_mean["Y"]

            r2_train = r2_score(y_train, train_predictions)
            r2_dev = r2_score(y_dev, dev_predictions)
            print('r2_score_train = {:.10f}'.format(r2_train))
            print('r2_score_dev = {:.10f}'.format(r2_dev))
            """ # time series length