Пример #1
0
 def test_random_seed(self):
     log.info("TEST random seed")
     df = pd.read_csv(PEYTON_FILE, nrows=512)
     set_random_seed(0)
     m = NeuralProphet(epochs=1)
     metrics_df = m.fit(df, freq="D")
     future = m.make_future_dataframe(df,
                                      periods=10,
                                      n_historic_predictions=10)
     forecast = m.predict(future)
     checksum1 = sum(forecast["yhat1"].values)
     set_random_seed(0)
     m = NeuralProphet(epochs=1)
     metrics_df = m.fit(df, freq="D")
     future = m.make_future_dataframe(df,
                                      periods=10,
                                      n_historic_predictions=10)
     forecast = m.predict(future)
     checksum2 = sum(forecast["yhat1"].values)
     set_random_seed(1)
     m = NeuralProphet(epochs=1)
     metrics_df = m.fit(df, freq="D")
     future = m.make_future_dataframe(df,
                                      periods=10,
                                      n_historic_predictions=10)
     forecast = m.predict(future)
     checksum3 = sum(forecast["yhat1"].values)
     log.debug("should be same: {} and {}".format(checksum1, checksum2))
     log.debug("should not be same: {} and {}".format(checksum1, checksum3))
     assert math.isclose(checksum1, checksum2)
     assert not math.isclose(checksum1, checksum3)
Пример #2
0
    #ensure minimum forecast is zero
    # def gt0(x):
    #     if x > 0:
    #         return x
    #     else:
    #         return 0
    
    #df.loc[:,'Order_Demand'] = df['Order_Demand'].apply(gt0)
    df.loc[:,'Order_Demand'] = df['Order_Demand'].apply(lambda x: 0 if x < 0 else x)
    df.to_pickle("DATA/forecast-demand.pkl")
    

if __name__ == '__main__':
    from neuralprophet import NeuralProphet, set_random_seed
    # clean_and_save()
    set_random_seed(42)
    df = pd.read_pickle("DATA/forecast-demand.pkl")
    # df.loc[:,'Order_Demand'] = df['Order_Demand'].apply(lambda x: math.log(x+1))
    products = df.groupby('Product_Code')
    
    # prodmed, prodmax = products.median(),products.max()
    # print(prodmin.head(10))
    
    # _ = sns.boxplot(y=prodmed['Order_Demand'])
    # _ = sns.boxplot(y=prodmax['Order_Demand'])
    # plt.show()
    #describe.reset_index().plot(x='Date')
    # test one product for forecasting
    
    Product_1766 = (products.resample('D')
                    .median()
Пример #3
0
import pandas as pd
from neuralprophet import NeuralProphet, set_random_seed
from pandas import DataFrame

from utils import DAYS_OF_PREDICTION

set_random_seed(0)


def predictions(df: DataFrame) -> DataFrame:
    """
    Make predictions about
    :param df: Dataframe to make the predictions
    :return:
    """
    m = NeuralProphet()
    m.fit(df, freq='D')
    future = m.make_future_dataframe(df, periods=DAYS_OF_PREDICTION)
    forecast = m.predict(future)
    forecast['ds'] = pd.to_datetime(forecast['ds']).dt.strftime('%Y-%m-%d')
    forecast = forecast.set_index('ds')
    forecast.rename(columns={'yhat1': 'currency'}, inplace=True)
    forecast = forecast.round(2)
    return forecast