Антон Конов
Антон Конов

Reputation: 11

ValueError: Each entry in features must be either an int, a string, or an iterable of size at most 2

When using a variable containing features, an error is generated, when inserting features directly, there are no problems

a=['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude']

def modell(data, metka, ftrs):
  X = data.drop([metka], axis=1)
  y = data[metka]
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0)
  model = XGBRegressor()
  model.fit(X_train, y_train)
  y_pred = model.predict(X)
  print('OK')

  features = [ftrs]  
  disp = PartialDependenceDisplay.from_estimator(model, X, features=features, kind='average')
  return 'NICE'

/usr/local/lib/python3.10/dist-packages/sklearn/inspection/_plot/partial_dependence.py in from_estimator(cls, estimator, X, features, categorical_features, feature_names, target, response_method, n_cols, grid_resolution, percentiles, method, n_jobs, verbose, line_kw, ice_lines_kw, pd_line_kw, contour_kw, ax, kind, centered, subsample, random_state)
    570                 ) from e
    571             if not 1 <= np.size(fxs) <= 2:
--> 572                 raise ValueError(
    573                     "Each entry in features must be either an int, "
    574                     "a string, or an iterable of size at most 2."

ValueError: Each entry in features must be either an int, a string, or an iterable of size at most 2.

if you substitute what is in a directly instead of ftrs everything works

I tried to rewrite the PDP library, it did not work for me

Upvotes: 0

Views: 64

Answers (0)

Related Questions