nabeel-oz / qlik-py-tools

Data Science algorithms for Qlik implemented as a Python Server Side Extension (SSE).
https://nabeel-oz.github.io/qlik-py-tools/
MIT License
185 stars 87 forks source link

Set expression on time series forecasting #24

Closed lalprasanth closed 5 years ago

lalprasanth commented 5 years ago

Hi Nabeel,

  Hope you are doing well.

I was trying to forecast using the facebook prophet model but ended up not getting the prediction of what I supposed to get. Basically, I have a measure to be calculated using the following expression

(1-(sum({$<Année=,Semaine=,Jour=,LieA={'Cause Fournisseur'}>}$(vValManq))/(sum({$<Année=,LieA={'Cause Fournisseur'},Semaine=,Jour=>}$(vValManq)) + Sum({$<Année=,Semaine=,Jour=>}$(vValSortie)))))*100

but I am just wondering how can it be manipulated to the following expression as you have used in your measure to forecast the values or is it something to be replaced with my measure.

Count({$<FORECAST_LINK_TYPE = {'Actual'}>} Distinct ACCIDENT_NO)

Whatever that has been written in the measure has to be added to the pytools.prophet function as well when we forecast the values. I hope you clarify my doubts.

nabeel-oz commented 5 years ago

You can use set analysis in the measure's expression as Qlik completes the calculation before sending the data to the SSE.

If you're using the forecast calendar described in the documentation you would need to add ,FORECAST_LINK_TYPE = {'Actual'} to your set analysis for each sum in your expression.

lalprasanth commented 5 years ago

Following expression is the one I've used to forecast the values, do you think this the right way to forecast the values? I also noticed the forecast is not accurate as you had in your forecast. can you give me your suggestion on this if you don't mind?

PyTools.Prophet(if(FORECAST_MONTH <= AddMonths(Max(Total [MonthAndYear]), $(vForecastPeriods)), FORECAST_MONTH), SUM({<Année=,Semaine=,Jour=>}$(vValStock))/SUM({<Année=,Semaine=,Jour=>}$(vValSortie)), 'freq=MS, return=yhat')

forecast trend

nabeel-oz commented 5 years ago

The forecast looks like what I'd expect from Prophet with just one year of monthly data. The algorithm has found a general trend and there is not enough data to determine seasonality in this case. You will need multiple years of data and/or lower granularity, i.e. weekly or daily data, for a better model.

nabeel-oz commented 5 years ago

Closing this issue as the original question has been addressed.