首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OrdinalEncoder‘object没有属性'_missing_indices’

OrdinalEncoder‘object没有属性'_missing_indices’
EN

Stack Overflow用户
提问于 2021-12-30 06:09:09
回答 1查看 727关注 0票数 0

我能够训练模型并成功地在Azure中部署端点。但是,当我测试端点时:它给出了下面的错误:

代码语言:javascript
复制
Failed to test real-time endpoint
{"status_code":400,"message":"'OrdinalEncoder' object has no attribute '_missing_indices'"}

在我的模型中,我使用了带ordinalEncoder的sklearn管道,运行在sklearn版本0.24.1上。守则的一部分如下:

代码语言:javascript
复制
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‘选项卡的测试数据:

代码语言:javascript
复制
{  "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"
}
EN

回答 1

Stack Overflow用户

发布于 2021-12-30 06:21:45

Failed to test real-time endpoint {"status_code":400,"message":"'OrdinalEncoder' object has no attribute '_missing_indices'"}错误意味着您缺少一个或多个索引,您可以尝试以下方法来处理它:

代码语言:javascript
复制
 # 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 self

您可以参考encoders.pysklearn.impute.MissingIndicator

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70528029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档