[Solved] applying onehotencoder on numpy array

Don’t use a new OneHotEncoder on test_data, use the first one, and only use transform() on it. Do this: test_data = onehotencoder_1.transform(test_data).toarray() Never use fit() (or fit_transform()) on testing data. The different number of columns are entirely possible because it may happen that test data dont contain some categories which are present in train data. … Read more