简体   繁体   中英

Error "Unknown label type: 'continuous'" when I use IterativeImputer with KNeighborsClassifier

I want to do a multiple imputation with IterativeImputer.

Here is the dataset (the original is from https://www.kaggle.com/jboysen/mri-and-alzheimers ):

alz_df_imp_categorical

The variables to impute are "educ" and "ses". As they are categorical I've choose to use a classifier (KNeighborsClassifier from sklearn). Predictors are continuous (except "sex").

This is the code:

# calling the  MICE class
KNN_class_estimator = KNeighborsClassifier()
mice_imputer =  IterativeImputer(random_state=0, estimator=KNN_class_estimator, initial_strategy ='mean')
# imputing the missing value with mice imputer
alz_df_imp_categorical = mice_imputer.fit_transform(alz_df_imp_categorical)

And the errors is:

"Unknown label type: 'continuous'"

In fact, fit_transform() function transforms the dataframe to an array and all variables are transformed in float type. Thus, the variables to predict are not categorical anymore because of this array transformation. Furthermore, only one type of variable are accepted in an array (so, i can't convert just the variables to predict in categorical and let the others in float). Thus, as the targets variables are float, the classifier can't works. So, I understand the error... but I don't know how to slove it.

I thought that, maybe, we can't apply a KNN classifier when they are many type of predictors (continuous and categorical). However, I have no problem with this when I use KNN classifier in R.

Do you have some ideas to slove this problem?

Thank you.

I just understood why it does not works. It's because IterativeImputer works only for continuous variables. So, apparently you can't apply multiple imputation for continuous variables with IterativeImputer. There is discussion about this here .

I saw it's possible to do simple imputation with categorical variables in python. However, it does not seem possible to do multiple imputation with this type of variables (anyway, I did not find).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM