コード例 #1
0
def Persistence_Method(data):
    per = data[['DateTime', 'WS95']].copy()
    per['V1'] = per['WS95'].copy()
    per['F1'] = per['WS95'].shift(1)
    per['F2'] = per['WS95'].shift(2)
    per['F3'] = per['WS95'].shift(3)
    per2 = DataRange(per, "2019-01-01 00:00", "2020-01-01 00:00")
    per2.to_csv('WS_PER_Result.csv')
コード例 #2
0
def Train_Model(Train_data, LB, LF):
    start_date1, stop_date1 = "2017-01-01 00:00", "2018-01-01 00:01"
    df_train = DataRange(Train_data, start_date1, stop_date1)
    df_train.reset_index(inplace=True, drop=True)
    x_train, y_train = shaping_one(df_train, LB, LF)
    start_date2, stop_date2 = "2018-01-01 00:00", "2019-01-01 00:01"
    df_test = DataRange(Train_data, start_date2, stop_date2)
    df_test.reset_index(inplace=True, drop=True)
    x_test, y_test = shaping_one(df_test, LB, LF)
    dimension = x_train.shape[1]
    timesteps = x_train.shape[2]
    model = my_model(dimension, timesteps, output=int(len(LF)))
    model.compile(loss='mean_squared_error', optimizer='adam')
    model_ckpt = ModelCheckpoint(filepath="./tmp2.h5",
                                 monitor="val_loss",
                                 save_best_only=True)
    history = model.fit(x_train,
                        y_train,
                        validation_data=(x_test, y_test),
                        batch_size=96,
                        epochs=50,
                        callbacks=[model_ckpt],
                        shuffle=True)
    model = tf.keras.models.load_model("./tmp2.h5")
    return model, history
コード例 #3
0
def Step_Error_ndim(df,Start_date,Stop_date,i,variable='WS'):
    df.fillna(method='ffill',inplace=True)
    df.reset_index(inplace=True,drop=True)
    df['V1_{}'.format(variable)].replace(0,0.001,inplace=True)
    data = DataRange(df,Start_date,Stop_date)
    WS_v = data['V1_{}'.format(variable)].copy()
    WS_f = data['F{}_{}'.format(i+1,variable)]
    MAE  = Mean_Absolute_Error(WS_v,WS_f)
    RMSE = Root_Mean_Square_Error(WS_v,WS_f)
    NMSE = Nor_Mean_Square_Error(WS_v,WS_f)
    print("{},{},{},{}".format(i+1,MAE,RMSE,NMSE))
    return MAE,RMSE,NMSE
コード例 #4
0
def Step_Error(df,Start_date,Stop_date,i):
    df.dropna(how='any',inplace=True)
    df.reset_index(inplace=True,drop=True)
    df['V1'].replace(0,0.001,inplace=True)
    data = DataRange(df,Start_date,Stop_date)
    WS_v = data['V1'].copy()
    WS_f = data['F{}'.format(i+1)]
    MAE  = Mean_Absolute_Error(WS_v,WS_f)
    RMSE = Root_Mean_Square_Error(WS_v,WS_f)
    NMSE = Nor_Mean_Square_Error(WS_v,WS_f)
    print("{},{},{},{}".format(i+1,MAE,RMSE,NMSE))
    return MAE,RMSE,NMSE
コード例 #5
0
def Plot_Step_Prediction(data, steps):
    date01 = '2019-02-07'
    date02 = '2019-02-08'
    df = DataRange(data, "{} 18:00".format(date01), "{} 03:01".format(date02))
    WS_v = df['V1'].copy()
    time = df['DateTime'].copy()
    u1 = time.iloc[0]
    u2 = time.iloc[-1]
    #naming = {1:'1st',2:'2nd',3:'3rd'}
    fig, (ax) = plt.subplots(steps,
                             1,
                             sharex=True,
                             figsize=(12, 9),
                             gridspec_kw={
                                 'wspace': 0,
                                 'hspace': 0.05
                             })
    for step in range(steps):
        WS_f = df['F{}'.format(step + 1)].copy()
        ax[step].plot(time,
                      WS_v,
                      label='Real',
                      marker='h',
                      color='black',
                      linewidth=2)
        ax[step].plot(time,
                      WS_f,
                      label='Predict',
                      linewidth=1,
                      linestyle=':',
                      marker='D',
                      color='blue')
        ax[step].legend(loc=2, fontsize=12)
        ax[step].tick_params(axis="x", labelsize=10, rotation=0)
        ax[step].tick_params(axis="y", labelsize=15)
        ax[step].set_xlim([u1, u2])
        ax[step].set_ylim([0, 26])
        ax[step].set_yticks([0, 5, 10, 15, 20, 25])
        ax[step].grid(True)
    ax[0].set_title("Wind Speed Prediction ({})".format(date01), fontsize=20)
    ax[step - 1].set_ylabel("Wind Speed (m/s)", fontsize=20)
    ax[step].set_xlabel("Time Series (Time Step=10min)", fontsize=20)
    ax[step].xaxis.set_major_locator(mdates.HourLocator())
    ax[step].xaxis.set_major_formatter(mdates.DateFormatter('%H00'))
    props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
    fig.text(0.80,
             0.656,
             '1st-Step Prediction',
             ha='center',
             size=16,
             bbox=props)
    fig.text(0.80,
             0.400,
             '2nd-Step Prediction',
             ha='center',
             size=16,
             bbox=props)
    fig.text(0.80,
             0.145,
             '3rd-Step Prediction',
             ha='center',
             size=16,
             bbox=props)