提问人:Luis Valencia 提问时间:9/19/2023 最后编辑:Luis Valencia 更新时间:9/20/2023 访问量:87
_nanquantile_dispatcher() 有一个意外的关键字参数“method”
_nanquantile_dispatcher() got an unexpected keyword argument 'method'
问:
我有一个大约有 6k 行的 pandaas 数据帧,有一个每小时的时间戳列和一个浮点数的值。
我正在使用 DARTS 进行预测和绘图
import pandas as pd
from darts import TimeSeries
df = dfTienen_final.toPandas()
df_no_duplicates = df.drop_duplicates(subset=['belgium_time'])
series = TimeSeries.from_dataframe(df_no_duplicates, "belgium_time", "avg_value", freq="H")
# Determine the number of rows in the DataFrame
num_rows = len(series)
# Set aside a percentage of the rows for validation (e.g., 10%)
validation_percentage = 10 # Adjust as needed
num_validation_points = (validation_percentage * num_rows) // 100 # Calculate the number of validation points
# Set aside the calculated number of rows as a validation series
train, val = series[:-num_validation_points], series[-num_validation_points:]
from darts.models import ExponentialSmoothing
model = ExponentialSmoothing()
model.fit(train)
prediction = model.predict(len(val), num_samples=1000)
然后是这个:
import matplotlib.pyplot as plt
series.plot()
prediction.plot(label="forecast", low_quantile=0.05, high_quantile=0.95)
plt.legend()
但是,我在绘图中收到此错误
_nanquantile_dispatcher() 有一个意外的关键字参数“method”
追踪
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File <command-3591413550716749>, line 4
1 import matplotlib.pyplot as plt
3 series.plot()
----> 4 prediction.plot(label="forecast", low_quantile=0.05, high_quantile=0.95)
5 plt.legend()
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c1295c6b-8422-4d69-982b-173176ff6a3d/lib/python3.10/site-packages/darts/timeseries.py:3820, in TimeSeries.plot(self, new_plot, central_quantile, low_quantile, high_quantile, default_formatting, label, max_nr_components, ax, *args, **kwargs)
3818 central_series = comp.mean(dim=DIMS[2])
3819 else:
-> 3820 central_series = comp.quantile(q=central_quantile, dim=DIMS[2])
3821 else:
3822 central_series = comp.mean(dim=DIMS[2])
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c1295c6b-8422-4d69-982b-173176ff6a3d/lib/python3.10/site-packages/xarray/core/dataarray.py:5123, in DataArray.quantile(self, q, dim, method, keep_attrs, skipna, interpolation)
5015 def quantile(
5016 self: T_DataArray,
5017 q: ArrayLike,
(...)
5022 interpolation: QuantileMethods | None = None,
5023 ) -> T_DataArray:
5024 """Compute the qth quantile of the data along the specified dimension.
5025
5026 Returns the qth quantiles(s) of the array elements.
(...)
5120 The American Statistician, 50(4), pp. 361-365, 1996
5121 """
-> 5123 ds = self._to_temp_dataset().quantile(
5124 q,
5125 dim=dim,
5126 keep_attrs=keep_attrs,
5127 method=method,
5128 skipna=skipna,
5129 interpolation=interpolation,
5130 )
5131 return self._from_temp_dataset(ds)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c1295c6b-8422-4d69-982b-173176ff6a3d/lib/python3.10/site-packages/xarray/core/dataset.py:8035, in Dataset.quantile(self, q, dim, method, numeric_only, keep_attrs, skipna, interpolation)
8029 if name not in self.coords:
8030 if (
8031 not numeric_only
8032 or np.issubdtype(var.dtype, np.number)
8033 or var.dtype == np.bool_
8034 ):
-> 8035 variables[name] = var.quantile(
8036 q,
8037 dim=reduce_dims,
8038 method=method,
8039 keep_attrs=keep_attrs,
8040 skipna=skipna,
8041 )
8043 else:
8044 variables[name] = var
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c1295c6b-8422-4d69-982b-173176ff6a3d/lib/python3.10/site-packages/xarray/core/variable.py:2292, in Variable.quantile(self, q, dim, method, keep_attrs, skipna, interpolation)
2288 axis = np.arange(-1, -1 * len(dim) - 1, -1)
2290 kwargs = {"q": q, "axis": axis, "method": method}
-> 2292 result = apply_ufunc(
2293 _wrapper,
2294 self,
2295 input_core_dims=[dim],
2296 exclude_dims=set(dim),
2297 output_core_dims=[["quantile"]],
2298 output_dtypes=[np.float64],
2299 dask_gufunc_kwargs=dict(output_sizes={"quantile": len(q)}),
2300 dask="parallelized",
2301 kwargs=kwargs,
2302 )
2304 # for backward compatibility
2305 result = result.transpose("quantile", ...)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c1295c6b-8422-4d69-982b-173176ff6a3d/lib/python3.10/site-packages/xarray/core/computation.py:1207, in apply_ufunc(func, input_core_dims, output_core_dims, exclude_dims, vectorize, join, dataset_join, dataset_fill_value, keep_attrs, kwargs, dask, output_dtypes, output_sizes, meta, dask_gufunc_kwargs, *args)
1205 # feed Variables directly through apply_variable_ufunc
1206 elif any(isinstance(a, Variable) for a in args):
-> 1207 return variables_vfunc(*args)
1208 else:
1209 # feed anything else through apply_array_ufunc
1210 return apply_array_ufunc(func, *args, dask=dask)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c1295c6b-8422-4d69-982b-173176ff6a3d/lib/python3.10/site-packages/xarray/core/computation.py:761, in apply_variable_ufunc(func, signature, exclude_dims, dask, output_dtypes, vectorize, keep_attrs, dask_gufunc_kwargs, *args)
756 if vectorize:
757 func = _vectorize(
758 func, signature, output_dtypes=output_dtypes, exclude_dims=exclude_dims
759 )
--> 761 result_data = func(*input_data)
763 if signature.num_outputs == 1:
764 result_data = (result_data,)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c1295c6b-8422-4d69-982b-173176ff6a3d/lib/python3.10/site-packages/xarray/core/variable.py:2286, in Variable.quantile.<locals>._wrapper(npa, **kwargs)
2284 def _wrapper(npa, **kwargs):
2285 # move quantile axis to end. required for apply_ufunc
-> 2286 return np.moveaxis(_quantile_func(npa, **kwargs), 0, -1)
File <__array_function__ internals>:4, in nanquantile(*args, **kwargs)
TypeError: _nanquantile_dispatcher() got an unexpected keyword argument 'method'
软件包版本: 飞镖 0.26.0 熊猫 2.0.3 numpy 1.26.0
一些数据
----+-----+-----+-------------------+------------------+--------------------+----------+------------------+------------------+------------------+------------------+------+-------+------------------+-------------------+-------+-------------------+-------------------+-------------------+-------------------+-------------------+-------------------+---------+----------------------+
| kp| min| max| timestamp_hour| avg_value| value_diff|percentage| moving_avg_7h| moving_avg_30h| 5sma| mean|stddev|z_score| smoothed_value| dt_iso|rain_1h| belgium_time| Rain_cumulative_2h| Rain_cumulative_3h| Rain_cumulative_4h| Rain_cumulative_5h| Rain_cumulative_6h|dry_group|dry_hours_within_group|
+----+-----+-----+-------------------+------------------+--------------------+----------+------------------+------------------+------------------+------------------+------+-------+------------------+-------------------+-------+-------------------+-------------------+-------------------+-------------------+-------------------+-------------------+---------+----------------------+
|0090|150.0|848.0|2022-07-13 10:00:00|112.41159858703614| 0.0| 0.0|112.41159858703614|112.41159858703614|112.41159858703614|112.41159858703614| 0.0| 0.0|112.41159858703614|2022-07-13 12:00:00| 0.0|2022-07-13 10:00:00| 0.0| 0.0| 0.0| 0.0| 0.0| NULL| 0|
|0090|150.0|848.0|2022-07-13 11:00:00|108.46443377043072| -3.9471648166054223| 0.0|110.43801617873342|110.43801617873342|110.43801617873342|110.43801617873342| 0.0| 0.0|110.43801617873342|2022-07-13 13:00:00| 0.0|2022-07-13 11:00:00| 0.0| 0.0| 0.0| 0.0| 0.0| NULL| 1|
|0090|150.0|848.0|2022-07-13 12:00:00|109.19111235245414| 0.7266785820234247| 0.0|110.02238156997366|110.02238156997366|110.02238156997366|110.02238156997366| 0.0| 0.0|110.02238156997366|2022-07-13 14:00:00| 0.0|2022-07-13 12:00:00| 0.0| 0.0| 0.0| 0.0| 0.0| NULL| 2|
|0090|150.0|848.0|2022-07-13 13:00:00|112.27772883365029| 3.0866164811961454| 0.0| 110.5862183858928| 110.5862183858928| 110.5862183858928| 110.5862183858928| 0.0| 0.0| 110.5862183858928|2022-07-13 15:00:00| 0.0|2022-07-13 13:00:00| 0.0| 0.0| 0.0| 0.0| 0.0| NULL| 3|
|0090|150.0|848.0|2022-07-13 14:00:00|111.91993414837381|-0.35779468527647396| 0.0|110.85296153838901|110.85296153838901|110.85296153838901|110.85296153838901| 0.0| 0.0|110.85296153838901|2022-07-13 16:00:00| 0.0|2022-07-13 14:00:00| 0.0| 0.0| 0.0| 0.0| 0.0| NULL| 4|
答: 暂无答案
上一个:将 Pandas 系列从 Timedelta 转换为微秒
下一个:高效跟踪数据修订
评论
df['ordinal'] = df.belgium_time.map(pd.Timestamp.toordinal)