1 # ==================================================================================
2 # Copyright (c) 2020 HCL Technologies Limited.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ==================================================================================
20 from qptrain import PROCESS
23 def forecast(data, cid, nobs=1):
25 forecast the time series using the saved model.
27 ps = PROCESS(data.copy())
31 pred = data.tail(1).values
32 if os.path.isfile('src/'+cid) and not ps.constant():
33 model = joblib.load('src/'+cid)
34 pred = model.forecast(y=data.values, steps=nobs)
36 df_f = pd.DataFrame(pred, columns=data.columns)
37 df_f.index = pd.date_range(start=data.index[-1], freq='10ms', periods=len(df_f))
38 df_f = df_f[data.columns].fillna(0).astype(int)
39 df_f = ps.invert_transformation(data, df_f)