如何解决如何解决 AttributeError: 'NoneType' 对象没有属性 'CONTENT_TYPE'
我正在按照教程在 Sagemaker 上使用 MXNET 来开发推荐引擎。
执行以下单元格后,我收到 AttributeError: 'nonetype' object has no attribute 'CONTENT_TYPE'
test_preds= []
for array in np.array_split(test_df[['customer_id','product_id']].values,40):
test_preds +=
predictor.predict(json.dumps({'customer_id':array[:,0].tolist(),'product_id':array[:,1].tolist()}))
test_preds = np.array(test_preds)
print('MSE:',np.mean((test_df['star_rating'] -test_preds))**2)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-38-a830dbc6ac84> in <module>
2 for array in np.array_split(test_df[['customer_id',40):
3 test_preds += predictor.predict(json.dumps({'customer_id':array[:,----> 4 'product_id':array[:,1].tolist()}))
5 test_preds = np.array(test_preds)
6 print('MSE:',np.mean((test_df['star_rating'] -test_preds))**2)
~/anaconda3/envs/amazonei_mxnet_p36/lib/python3.6/site-packages/sagemaker/predictor.py in predict(self,data,initial_args,target_model,target_variant,inference_id)
132
133 request_args = self._create_request_args(
--> 134 data,inference_id
135 )
136 response = self.sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)
~/anaconda3/envs/amazonei_mxnet_p36/lib/python3.6/site-packages/sagemaker/predictor.py in _create_request_args(self,inference_id)
158
159 if "ContentType" not in args:
--> 160 args["ContentType"] = self.content_type
161
162 if "Accept" not in args:
~/anaconda3/envs/amazonei_mxnet_p36/lib/python3.6/site-packages/sagemaker/predictor.py in content_type(self)
511 def content_type(self):
512 """The MIME type of the data sent to the inference endpoint."""
--> 513 return self.serializer.CONTENT_TYPE
514
515 @property
AttributeError: 'nonetype' object has no attribute 'CONTENT_TYPE'
**predictor 是训练模型的生产端点
test_df 在这里定义
df_titles = df[['customer_id','product_title','product_id','star_rating']]
df = df[['customer_id','star_rating']]
customers = df['customer_id'].value_counts()
products = df['product_id'].value_counts()
# Filter long-tail
customers = customers[customers >= 5]
products = products[products >= 10]
reduced_df_titles = df_titles.merge(pd.DataFrame({'customer_id':
customers.index})).merge(pd.DataFrame({'product_id':
products.index}))
reduced_df = df.merge(pd.DataFrame({'customer_id':
customers.index})).merge(pd.DataFrame({'product_id':
products.index}))
customers = reduced_df['customer_id'].value_counts()
products = reduced_df['product_id'].value_counts()
# Number users and items
#Next,we'll number each user and item,giving them their own
sequential index. This will allow us to hold
#the information in a sparse format where the sequential indices
indicate the row and column in our ratings matrix.
customer_index = pd.DataFrame({'customer_id': customers.index,'user':
np.arange(customers.shape[0])})
product_index = pd.DataFrame({'product_id': products.index,'item':
np.arange(products.shape[0])})
reduced_df = reduced_df.merge(customer_index).merge(product_index)
reduced_df_titles =
reduced_df_titles.merge(customer_index).merge(product_index)
# Split train and test
train_df,test_df = train_test_split(reduced_df,test_size=0.2,random_state=0)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。