我能够训练模型并成功地在Azure中部署端点。但是,当我测试端点时:它给出了下面的错误:
Failed to test real-time endpoint
{"status_code":400,"message":"'OrdinalEncoder' object has no attribute '_missing_indices'"}在我的模型中,我使用了带ordinalEncoder的sklearn管道,运行在sklearn版本0.24.1上。守则的一部分如下:
numeric_transformer = Pipeline(steps=[
('imputer', SimpleImputer(strategy='most_frequent'))
])
categorical_transformer = Pipeline(steps=[
('ordinal', OrdinalEncoder(handle_unknown='ignore'))
])
features_preprocessor = ColumnTransformer(
transformers=[
('numeric', numeric_transformer, cols_tofill.values),
('categorical', categorical_transformer, ['Country','Status'])
], remainder='passthrough')一直在尝试调试,但是如果我不知道这个错误意味着什么,那就很困难了。有人能告诉我吗?非常感谢你的帮助。
下面是我传递给Azure端点的' test‘选项卡的测试数据:
{ "data": [{"Country": "Japan",
"Year": 2021,
"Status": "Developed",
"Adult_Mortality": 52,
"Infant_Deaths": 1,
"Alcohol": 1.9,
"Percentage_Expenditure": 8000,
"Hepatitis_B": 98,
"Measles": 0,
"BMI": 33,
"Under-five_Deaths": 0,
"Polio": 90,
"Total_Expenditure": 5,
"Diphtheria": 99,
"HIV/AIDS": 0.1,
"GDP": 57000,
"Population": 6000000,
"thinness_1-19_years": 2,
"thinness_5-9_years": 2,
"Income_composition_of_resources": 0.9,
"Schooling": 15}],
"method": "predict"
}发布于 2021-12-30 06:21:45
此Failed to test real-time endpoint {"status_code":400,"message":"'OrdinalEncoder' object has no attribute '_missing_indices'"}错误意味着您缺少一个或多个索引,您可以尝试以下方法来处理它:
# stores the missing indices per category
self._missing_indices = {}
for cat_idx, categories_for_idx in enumerate(self.categories_):
for i, cat in enumerate(categories_for_idx):
if is_scalar_nan(cat):
self._missing_indices[cat_idx] = i
continue
if np.dtype(self.dtype).kind != "f" and self._missing_indices:
raise ValueError(
"There are missing values in features "
f"{list(self._missing_indices)}. For OrdinalEncoder to "
"passthrough missing values, the dtype parameter must be a "
"float"
)
return selfhttps://stackoverflow.com/questions/70528029
复制相似问题