interpret icon indicating copy to clipboard operation
interpret copied to clipboard

Exception: Could not unify data of type: <class 'pandas.core.frame.DataFrame'>

Open NadeemNicoR opened this issue 2 years ago • 0 comments

I have multiple targets and i am trying to use the following

  1. p = Pipeline([*steps, ('regressor', MultiOutputRegressor(reg()))]) blackbox_model = p.fit(X_train_val, y_train_val)

  2. blackbox_perf = RegressionPerf(blackbox_model.predict).explain_perf(X_test, y_test, name='Blackbox') show(blackbox_perf)

till fitting the pipeline works perfectly fine and then all of a sudden when i try blackbox_perf it throws the error

ERROR: `Exception Traceback (most recent call last) Input In [59], in <cell line: 4>() 1 from interpret import show 2 from interpret.perf import RegressionPerf ----> 4 blackbox_perf = RegressionPerf(blackbox_model.predict).explain_perf(X_test, y_test, name='Blackbox') 5 show(blackbox_perf)

File ~\anaconda3\lib\site-packages\interpret\perf\regression.py:45, in RegressionPerf.explain_perf(self, X, y, name) 42 if name is None: 43 name = gen_name_from_class(self) ---> 45 X, y, self.feature_names, self.feature_types = unify_data( 46 X, y, self.feature_names, self.feature_types, missing_data_allowed=True 47 ) 49 predict_fn = unify_predict_fn(self.predict_fn, X) 50 scores = predict_fn(X)

File ~\anaconda3\lib\site-packages\interpret\utils\all.py:329, in unify_data(data, labels, feature_names, feature_types, missing_data_allowed) 326 log.error(msg) 327 raise ValueError(msg) --> 329 new_labels = unify_vector(labels) 331 # NOTE: Until missing handling is introduced, all methods will fail at data unification stage if present. 332 new_data_has_na = ( 333 True if new_data is not None and pd.isnull(new_data).any() else False 334 )

File ~\anaconda3\lib\site-packages\interpret\utils\all.py:238, in unify_vector(data) 236 msg = "Could not unify data of type: {0}".format(type(data)) 237 log.warning(msg) --> 238 raise Exception(msg) 240 return new_data

Exception: Could not unify data of type: <class 'pandas.core.frame.DataFrame'>`

`numeric_transformer = Pipeline( steps=[("imputer", SimpleImputer(strategy="mean", missing_values=np.nan)), ("scaler", StandardScaler())] )

categorical_transformer = Pipeline( steps=[("imputer", SimpleImputer(missing_values=None, strategy='most_frequent')), ("encoder", OneHotEncoder(handle_unknown="ignore"))] )

preprocessor = ColumnTransformer( transformers=[ ("num", numeric_transformer, numeric_features), ("cat", categorical_transformer, categorical_features), ] ) steps = [('preprocessor', preprocessor)]`

above are my transformations that i am appying on the data if in case you need more info

NadeemNicoR avatar Jul 14 '22 13:07 NadeemNicoR