Scikit Learn OneHotEncoder fit and transform Error: ValueError: X has different shape than during fitting

后端 未结 2 1619
难免孤独
难免孤独 2020-11-30 14:59

Below is my code.

I know why the error is occurring during transform. It is because of the feature list mismatch during fit and transform. How can i solve this? How

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 15:19

    You encoder is fitted on refreshed_df which contains 10 columns and your refreshed_df1 contains only 4, literally what it is reported in the error. You have either to delete the columns not appearing on your refreshed_df1 or just fit your encoder to a new version of refreshed_df that only contains the 4 columns appearing in refreshed_df1 .

提交回复
热议问题