2

I am trying to apply feature selection method using SelectKBest with chi2 to select top 15 features from the data but it comes with an error

ValueError: Input X must be non-negative

Can any one help me out with this error. Below is the code that i have used


x = data.drop('TARGET_B', axis='columns')
x = x.drop('TARGET_D', axis='columns')
y= data.TARGET_B

x_train, x_test, y_train, y_test = model_selection.train_test_split(x,
        y, test_size=0.20, random_state=None)

select_feature = SelectKBest(chi2, k=15).fit(x_train, y_train)

Shah
  • 21
  • 1
  • 6
  • What is the value of *Input X*? – Scott Hunter Jan 09 '20 at 15:34
  • Possible dupe of [this](https://stackoverflow.com/a/46608239/10682164). If you have to go this route, you might be able to use a [MinMaxScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html#sklearn.preprocessing.MinMaxScaler) to preprocess your input data. I suggest forming a [Pipeline](https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html) for this. – totalhack Jan 09 '20 at 15:44

0 Answers0