导入错误:无法从“darts.models”导入名称“MovingAverage”

问题描述 投票:0回答:1

当我尝试导入 MovingAverage 时,出现导入错误。

ImportError: cannot import name 'MovingAverage' from 'darts.models' (/usr/local/lib/python3.10/dist-packages/darts/models/__init__.py)

当然,我确实安装了darts。

!pip install darts

这是源代码片段

from darts.models import MovingAverage
# Oil Price

oil = TimeSeries.from_dataframe(df_oil, time_col = 'date', value_cols = ['dcoilwtico'], freq = 'D')

oil = oil.astype(np.float32)

# Transform
oil_filler = MissingValuesFiller(verbose=False, n_jobs=-1, name="Filler")
oil_scaler = Scaler(verbose=False, n_jobs=-1, name="Scaler")
oil_pipeline = Pipeline([oil_filler, oil_scaler])
oil_transformed = oil_pipeline.fit_transform(oil)

# Moving Averages for Oil Price
oil_moving_average_7 = MovingAverage(window=7)
oil_moving_average_28 = MovingAverage(window=28)
python dart importerror
1个回答
0
投票

darts是什么版本?

pip show darts

我建议首先检查您安装的 darts 版本,并确保它是最新版本或包含 MovingAverage 类的版本。

这是我运行代码片段的输出,运行后解决了导入错误

!pip install darts

Name: darts
Version: 0.27.0
Summary: A python library for easy manipulation and forecasting of time series.
Home-page: https://unit8co.github.io/darts/
Author: 
Author-email: 
License: Apache License 2.0
Location: /usr/local/lib/python3.11/site-packages
Requires: holidays, joblib, matplotlib, nfoursid, numpy, pandas, pmdarima, pyod, pytorch-lightning, requests, scikit-learn, scipy, shap, statsforecast, statsmodels, tbats, tensorboardX, torch, tqdm, typing-extensions, xarray, xgboost
Required-by: 

如果darts没有安装正确,可以运行

pip uninstall darts
pip install darts
© www.soinside.com 2019 - 2024. All rights reserved.