如何解决时间序列预测DeepAR:AttributeError:“系列”对象没有属性“ freq”
UPDATE1:问题可能是我无法在SageMaker Studio Notebook上更新熊猫。 熊猫版本“ 1.0.1”
我正在运行The following Entity Framework Core commands are available.
Cmdlet Description
-------------------------- ---------------------------------------------------
Add-Migration Adds a new migration.
Drop-Database Drops the database.
Get-DbContext Gets information about a DbContext type.
Remove-Migration Removes the last migration.
Scaffold-DbContext Scaffolds a DbContext and entity types for a database.
Script-DbContext Generates a SQL script from the current DbContext.
Script-Migration Generates a SQL script from migrations.
Update-Database Updates the database to a specified migration.
,并按照存储库https://github.com/aws-samples/amazon-sagemaker-stock-prediction/tree/master/notebooks中的说明提供了模块dbg-deepar.ipynb
。
我正在运行下面的DeepARPredictor类中的预测作业。
deepar_util.py
deepar_util.py
class DeepARPredictor(sagemaker.predictor.RealTimePredictor):
def __init__(self,*args,**kwargs):
super().__init__(*args,content_type=sagemaker.content_types.CONTENT_TYPE_JSON,**kwargs)
def predict(self,ts,cat=None,dynamic_feat=None,num_samples=100,return_samples=False,quantiles=["0.1","0.5","0.9"]):
"""Requests the prediction of for the time series listed in `ts`,each with the (optional)
corresponding category listed in `cat`.
ts -- `pandas.Series` object,the time series to predict
cat -- integer,the group associated to the time series (default: None)
num_samples -- integer,number of samples to compute at prediction time (default: 100)
return_samples -- boolean indicating whether to include samples in the response (default: False)
quantiles -- list of strings specifying the quantiles to compute (default: ["0.1","0.9"])
Return value: list of `pandas.DataFrame` objects,each containing the predictions
"""
prediction_time = ts.index[-1] + pd.Timedelta(1,unit='D')
quantiles = [str(q) for q in quantiles]
req = self.__encode_request(ts,cat,dynamic_feat,num_samples,return_samples,quantiles)
res = super(DeepARPredictor,self).predict(req)
return self.__decode_response(res,ts.index.freq,prediction_time,return_samples)
def __encode_request(self,quantiles):
instance = series_to_dict(ts,cat if cat is not None else None,dynamic_feat if dynamic_feat else None)
configuration = {
"num_samples": num_samples,"output_types": ["quantiles","samples"] if return_samples else ["quantiles"],"quantiles": quantiles
}
http_request_data = {
"instances": [instance],"configuration": configuration
}
return json.dumps(http_request_data).encode('utf-8')
def __decode_response(self,response,freq,return_samples):
# we only sent one time series so we only receive one in return
# however,if possible one will pass multiple time series as predictions will then be faster
predictions = json.loads(response.decode('utf-8'))['predictions'][0]
prediction_length = len(next(iter(predictions['quantiles'].values())))
prediction_index = pd.DatetimeIndex(start=prediction_time,freq=freq,periods=prediction_length)
if return_samples:
dict_of_samples = {'sample_' + str(i): s for i,s in enumerate(predictions['samples'])}
else:
dict_of_samples = {}
return pd.DataFrame(data={**predictions['quantiles'],**dict_of_samples},index=prediction_index)
def set_frequency(self,freq):
self.freq = freq
我调用了DeepARPredictor类来预测以下功能:
dbg-deepar.ipynb
我收到的错误消息:
predictor = DeepARPredictor(estimator_job)
ts,observed = util.query_for_stock('BMW',target_column,covariate_columns,stock_data_series,prediction_length)
prediction = predictor.predict(ts=ts,dynamic_feat = dynamic_feat,quantiles=[0.10,0.5,0.90],return_samples=False)
我意识到的是,箭头指向的错误(函数predict())不是问题所在,而是整个函数。但是我看不到带有该功能的问题。
有人可以帮我解释一下吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。