1

I am using mlxtend lib for bias,variance calculation. The code is,

y=df[target]
x=df.drop(target,axis=1)
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1)
model = LinearRegression()
mse, bias, var = bias_variance_decomp(model, x_train, y_train, x_test, y_test, loss='mse', num_rounds=200, random_seed=1)

I received the following error,

raise KeyError(f"None of [{key}] are in the [{axis_name}]")

KeyError: "None of [Int64Index([ 37, 235,  72, 255, 203, 133, 144, 129,  71, 237,\n            ...\n            221, 244, 204, 105,  36, 112, 144, 158, 115, 106],\n           dtype='int64', length=292)] are in the [columns]"

I tried to use the Xy values as numpy values. That also create error.

Any suggestion on this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
sundarr
  • 385
  • 2
  • 8
  • Can you please provide a minimal, reproducible example of your code? (https://stackoverflow.com/help/minimal-reproducible-example) The dataframe "df" your code is using for instance is not provided, so your error can not be reproduced. – Kim Tang Sep 03 '20 at 07:09
  • What error did you get in the second case? – jtlz2 Nov 07 '22 at 14:49
  • You should be passing numpy arrays not pandas dataframes, so use `x_train` -> `x_train.values` (etc). – jtlz2 Nov 07 '22 at 14:50
  • Does this answer your question? [Bias variance tradeoff KeyError](https://stackoverflow.com/questions/63668892/bias-variance-tradeoff-keyerror) – jtlz2 Nov 07 '22 at 14:52

0 Answers0