Akram
Akram

Reputation: 1

I'm getting this error: "Shape of passed values is (55, 93315), indices imply (68, 93315)" when applying the Imputer

Here is my code

` from sklearn.preprocessing import Imputer

    imp = Imputer(strategy='median')
    imputed_df = pd.DataFrame(imp.fit_transform(df1), columns=df1.columns)`

The error message: "Shape of passed values is (55, 93315), indices imply (68, 93315)"

The shape of df1 is: (93315, 68) but the shape of imputed_df is: (93315, 55) Any explanation??

Upvotes: 0

Views: 787

Answers (1)

J. Alan
J. Alan

Reputation: 35

Check for columns in the df1, there might be having columns with all NaN values or missing values.

From Documentation:

Columns which only contained missing values at :meth:fit are discarded upon :meth:transform if strategy is not "constant".

The error is thrown by the pandas dataframe constructor, implying mismatch, as the fit_transform of sklearn imputer drops the columns containing all missing values. The documentation states the same. Read more here https://scikit-learn.org/stable/modules/generated/sklearn.impute.SimpleImputer.html! https://github.com/scikit-learn/scikit-learn/blob/fd237278e/sklearn/impute/_base.py#L205

Upvotes: 1

Related Questions