Diego Menezes
08/31/2023, 3:26 PMfrom statsforecast.utils import ConformalIntervals
gives the error:
ImportError: cannot import name 'ConformalIntervals' from 'statsforecast.utils'
Has anyone else experienced this? Python = 3.10.9 & statsforecast = 1.5.0
Thanks a bunch.Evan Miller
08/31/2023, 8:08 PMimport pandas as pd
import numpy as np
from mlforecast import MLForecast
import lightgbm as lgb
cols = 4 # col 0 is target, col 1 is weights, cols 2 and 3 are features
rows = 20000
data=np.random.rand(rows,cols)
columns = ['y','weight','feat_1','feat_2']
data_df = pd.DataFrame(data[:,0:4], columns=columns)
data_df['unique_id'] = 1
data_df['ds']= [i for i in range(0, rows)]
model_1 = MLForecast(
models={
'LGBM': lgb.LGBMRegressor()
},
freq=1,
lags = [1, 2],
)
prep = model_1.preprocess(data_df, static_features = None, dropna = False)
train_weight = prep['weight']
train_x = prep.iloc[:,[2,3,6,7]]
train_y = prep['y']
model_1.models['LGBM'].fit(train_x,train_y,train_weight)
data_future = pd.DataFrame({'unique_id': [1,1,1],'ds':[rows,rows+1,rows+2], 'feat_1':[1,2,3], 'feat_2':[1,2,3]})
model_1.predict(3,X_df=data_future)
Yaping Lang
09/04/2023, 7:37 AMTraceback (most recent call last):
File "/Users/lilypad/Documents/Code/timegpt/test1.py", line 19, in <module>
sf.plot(df, fcst_df, level=[80, 90], max_insample_length=24 * 5)
File "/opt/homebrew/lib/python3.11/site-packages/statsforecast/core.py", line 1789, in plot
axes[idx, idy].fill_between(
File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/__init__.py", line 1446, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/axes/_axes.py", line 5425, in fill_between
return self._fill_between_x_or_y(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/axes/_axes.py", line 5330, in _fill_between_x_or_y
ind, dep1, dep2 = map(
^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/numpy/ma/core.py", line 2360, in masked_invalid
return masked_where(~(np.isfinite(getdata(a))), a, copy=copy)
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
python script is :
import pandas as pd
import os
from nixtlats import TimeGPT
from statsforecast import StatsForecast as sf
print(os.environ)
df = pd.read_csv('<https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short.csv>')
timegpt = TimeGPT(token=os.environ['TIMEGPT_TOKEN'])
fcst_df = timegpt.forecast(df, h=24, level=[80, 90])
print("NaN count in df:")
print(df.isna().sum())
print("NaN count in fcst_df:")
print(fcst_df.isna().sum())
sf.plot(df, fcst_df, level=[80, 90], max_insample_length=24 * 5)
J.
09/06/2023, 8:39 AM# Find timeseries with least data
min_ts_count = big_df_for_stats.groupby(by="unique_id").count()["y"].min()
# This is the amount of minimum trained wanted for rolling! window
initial_training_size = 365
step_size = 4
h = 1
test_size_parameter = ((min_ts_count - initial_training_size)//step_size)
# This is the workaround to prevent the exception which happens when "(test_size-h)%step_size != 0"
test_size_parameter = test_size_parameter - (test_size_parameter%step_size) + h
res_df = sf.cross_validation(h=h, step_size=step_size, fitted=True, test_size=test_size_parameter, n_windows=None)
Evan Miller
09/06/2023, 10:31 PMEvan Miller
09/06/2023, 10:45 PMfrom utilsforecast import preprocessing as pr
import pandas as pd
import numpy as np
df = pd.DataFrame(
{
'unique_id': [0, 0, 0, 1, 1],
'ds': pd.to_datetime(['2018-11-11', '2018-11-18', '2018-12-02', '2018-11-11', '2018-12-02']),
'y': np.arange(5),
}
)
df1 = pr.fill_gaps(
df,
freq='W',
)
print(df)
print(df1)
##### OUTPUT ######
unique_id ds y
0 0 2018-11-11 0
1 0 2018-11-18 1
2 0 2018-12-02 2
3 1 2018-11-11 3
4 1 2018-12-02 4
unique_id ds y
0 0 2018-11-08 NaN
1 0 2018-11-15 NaN
2 0 2018-11-22 NaN
3 0 2018-11-29 NaN
4 1 2018-11-08 NaN
5 1 2018-11-15 NaN
6 1 2018-11-22 NaN
7 1 2018-11-29 NaN
This is happening because the numpy definition for week is bucketed starting on Thursdays:
np.datetime64(pd.to_datetime("2018-11-11"),'W')
##### OUTPUT ######
numpy.datetime64('2018-11-08')
If I comment out the last two lines of _determine_bound in the fill_gaps method, the problem is resolved:
def fill_gaps(
df: pd.DataFrame,
freq: str = 'W',
start: str = "per_serie",
end: str = "global",
id_col: str = "unique_id",
time_col: str = "ds",
) -> pd.DataFrame:
delta = np.timedelta64(1, freq) if isinstance(freq, str) else freq
times_by_id = df.groupby(id_col)[time_col].agg(["min", "max"])
starts = _determine_bound(start, freq, times_by_id, "min")
ends = _determine_bound(end, freq, times_by_id, "max") + delta
sizes = ((ends - starts) / delta).astype(np.int64)
times = np.concatenate(
[np.arange(start, end, delta) for start, end in zip(starts, ends)]
)
if isinstance(freq, str):
times = times.astype("datetime64[ns]", copy=False)
uids = np.repeat(times_by_id.index, sizes)
idx = pd.MultiIndex.from_arrays([uids, times], names=[id_col, time_col])
return df.set_index([id_col, time_col]).reindex(idx).reset_index()
def _determine_bound(bound, freq, times_by_id, agg) -> np.ndarray:
if bound == "per_serie":
out = times_by_id[agg].values
else:
# the following return a scalar
if bound == "global":
val = getattr(times_by_id[agg].values, agg)()
if isinstance(freq, str):
val = np.datetime64(val)
else:
if isinstance(freq, str):
# this raises a nice error message if it isn't a valid datetime
val = np.datetime64(bound)
else:
val = bound
out = np.full(times_by_id.shape[0], val)
#if isinstance(freq, str):
#out = out.astype(f"datetime64[{freq}]")
return out
df = pd.DataFrame(
{
'unique_id': [0, 0, 0, 1, 1],
'ds': pd.to_datetime(['2018-11-11', '2018-11-18', '2018-12-02', '2018-11-11', '2018-12-02']),
'y': np.arange(5),
}
)
df1 = fill_gaps(
df,
freq='W',
)
print(df)
print(df1)
##### OUTPUT #####
unique_id ds y
0 0 2018-11-11 0
1 0 2018-11-18 1
2 0 2018-12-02 2
3 1 2018-11-11 3
4 1 2018-12-02 4
unique_id ds y
0 0 2018-11-11 0.0
1 0 2018-11-18 1.0
2 0 2018-11-25 NaN
3 0 2018-12-02 2.0
4 1 2018-11-11 3.0
5 1 2018-11-18 NaN
6 1 2018-11-25 NaN
7 1 2018-12-02 4.0
However, with this change problems occur when the weekly bucketing of the data is not precise (i.e. if I accidentally put '2018-12-01' in it would error)J.
09/07/2023, 2:07 PMManuel
09/07/2023, 8:11 PMLinenBot
09/08/2023, 2:25 AMBWBarber
joined #general.steve tawk
09/08/2023, 9:07 AMMairon Cesar Simoes Chaves
09/08/2023, 3:27 PMApiError: status_code: 429, body: {'data': None, 'message': 'Too many requests', 'details': 'You have reached your request limit, email <mailto:ops@nixtla.io|ops@nixtla.io> to continue using the API', 'code': 'A20', 'requestID': 'CJA2TUG4YJ', 'support': 'If you have questions or need support, please email <mailto:ops@nixtla.io|ops@nixtla.io>'}
Brian Head
09/08/2023, 4:11 PMhanchen su
09/13/2023, 7:30 AMBrian Head
09/15/2023, 3:58 PMnixtla
package, which I can't find. I haven't had luck with google/stackoverflow searches. I did find one ticket/issue on the GitHub page about FFORMA (which would be great), but right now I'm just looking to do combo models of simple averages--with statsforecast and mlforecast models. Is this a feature I've just not been able to find or something perhaps in the works?
https://medium.com/@gosshhh9/nixtla-using-ensembling-method-for-time-series-e1d23964ac30Hernando Gaitán
09/18/2023, 3:34 AMArun Rajagopal
09/18/2023, 3:18 PMPatrick Baron
09/19/2023, 2:47 AMJ.
09/19/2023, 1:12 PMAkmal Soliev
09/19/2023, 7:57 PMLinenBot
09/20/2023, 11:54 AMGoostValley
joined #general.Hernando Gaitán
09/20/2023, 1:40 PMConor Curran
09/20/2023, 11:22 PMY C
09/21/2023, 9:33 AMPatrick Baron
09/21/2023, 6:14 PMDeepanjan Datta
09/24/2023, 4:24 PMDeepanjan Datta
09/24/2023, 5:05 PMViet Yen Nguyen
09/25/2023, 6:55 AMErik Samuel Case
09/25/2023, 5:33 PMDavid Wheeler
09/26/2023, 5:11 PMJohn Lashlee
09/26/2023, 7:05 PM/local_disk0/.ephemeral_nfs/envs/pythonEnv-6ba80c76-407b-4675-a454-0051f1cc3503/lib/python3.10/site-packages/statsforecast/arima.py1557 UserWarning:
xreg not required by this model, ignoring the provided regressorsI've been plumbing the source code and I think
forecast_arima
might be dispatching with a model that I don't intend it to (no exog regressors). Does anybody have any advice on how I can debug further?