@@ -0,0 +1,2269 @@
+import pandas as pd%0Aimport numpy as np%0Aimport pyaf.HierarchicalForecastEngine as hautof%0A%0Aimport datetime%0A%0A#get_ipython().magic('matplotlib inline')%0A%0Aimport pandas as pd%0A%0Afilename = %22https://raw.githubusercontent.com/antoinecarme/TimeSeriesData/master/Stat_FR_CommExt/merged/French_Wine_Export_in_Euros_Some_Countries.csv%22%0A%0AFrench_Wine_Export_in_Euros_DF = pd.read_csv(filename);%0AlDateColumn = 'Month';%0AFrench_Wine_Export_in_Euros_DF%5BlDateColumn%5D = French_Wine_Export_in_Euros_DF%5BlDateColumn%5D.apply(lambda x : datetime.datetime.strptime(x, %22%25Y-%25m-%25d%22))%0A%0AFrench_Wine_Export_in_Euros_DF.head(5)%0A%0A%0AWines = u%22ALSACE BEAUJOLAIS BORDEAUX BOURGOGNE CHAMPAGNE EUROPE FRANCE LANGUEDOC LOIRE OTHER RHONE%22.split();%0AWines = Wines%5B0:2%5D;%0AVariants = %5B'BLANC' , 'MOUSSEUX' , 'ROUGE'%5D;%0AVariants = %5B'BLANC' , 'ROUGE'%5D;%0ACountries = %5B'GB', 'US', 'DE', 'BE', 'CN', 'JP', 'CH', 'HK', 'NL', 'CA' , 'OTHER'%5D%0ARegions = %5B'EUROPE', 'AMERICA', 'EUROPE' , 'EUROPE' , 'ASIA' , 'ASIA' , 'EUROPE',  'ASIA', 'EUROPE' , 'AMERICA' , 'OTHER_REGION'%5D%0AlDict = dict(zip(Countries , Regions));%0A%0ACountries = Countries%5B0:6%5D%0A%0Arows_list = %5B%5D;%0Afor v in Variants:%0A    for w in Wines:%0A        for c in Countries:%0A            col = w + %22_%22 + v + %22_%22 + c;%0A            region = lDict%5Bc%5D%0A            if(col in French_Wine_Export_in_Euros_DF.columns):%0A                rows_list.append(%5Bcol , c , region , 'WORLD'%5D);%0A            %0AlLevels = %5B'Wine' , 'Country' , 'Region' , 'WORLD'%5D;%0AlHierarchy = %7B%7D;%0AlHierarchy%5B'Levels'%5D = lLevels;%0AlHierarchy%5B'Data'%5D = pd.DataFrame(rows_list, columns =  lLevels);%0AlHierarchy%5B'Type'%5D = %22Hierarchical%22;%0A    %0Aprint(lHierarchy%5B'Data'%5D.head(lHierarchy%5B'Data'%5D.shape%5B0%5D));%0A%0AlEngine = hautof.cHierarchicalForecastEngine()%0AlEngine.mOptions.mHierarchicalCombinationMethod = %22BU%22;%0AlEngine%0A%0AN = French_Wine_Export_in_Euros_DF.shape%5B0%5D;%0Atrain_df = French_Wine_Export_in_Euros_DF.head(N-4);%0AH = 4;%0AlSignalVar = %22Sales%22;%0A%0A# lEngine.mOptions.enable_slow_mode();%0A# lEngine.mOptions.mDebugPerformance = True;%0AlEngine.train(train_df , lDateColumn , lSignalVar, H, lHierarchy, None);%0A%0AlEngine.getModelInfo();%0AlEngine.standrdPlots(%22outputs/WineExport%22);%0A%0Adfapp_in = train_df.copy();%0Adfapp_in.tail()%0A%0Adfapp_out = lEngine.forecast(dfapp_in, H);%0Adfapp_out.to_csv(%22outputs/Hierarchical_WineExport_apply_out.csv%22)%0A

Add a Jupyter Notebook to demonstrate the use of Hierarchical Forecasting #9