Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError in feature_selection.mRMR #2

Open
vasi14 opened this issue Nov 4, 2020 · 0 comments
Open

KeyError in feature_selection.mRMR #2

vasi14 opened this issue Nov 4, 2020 · 0 comments

Comments

@vasi14
Copy link

vasi14 commented Nov 4, 2020

Hi, i tried using the mRMR selector as specified in the documentation

selector = mRMR(score_func='MIQ', k=10)
selector.fit(X, y)
X_transformed = selector.transform(X)

i get the below issue. i think the reason might be when we are calculating the num_features=len(X[0]) it is causing error, should we use .iloc method to access the dataframe using index. But i am not sure. Help needed

KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2894 try:
-> 2895 return self._engine.get_loc(casted_key)
2896 except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 0

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)
4 frames
in ()

---> 19 selector.fit(xtrain,ytrain)
20 X_transformed = selector.transform(df,3)

/content/MLMethods/feature_selection/mRMR.py in fit(self, X, y, k)
377 # select random feature to start search
378 if self.score_func == 'MID':
--> 379 self.selected_indices = MID(X, y, k)
380 elif self.score_func == 'MIQ':
381 self.selected_indices = MIQ(X, y, k)

/content/MLMethods/feature_selection/mRMR.py in MID(X, y, k)
52 # mutual information difference
53 def MID(X, y, k):
---> 54 num_features = len(X[0])
55 start_feature_index = random.randint(0, num_features-1)
56 selected_indices = set()

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in getitem(self, key)
2900 if self.columns.nlevels > 1:
2901 return self._getitem_multilevel(key)
-> 2902 indexer = self.columns.get_loc(key)
2903 if is_integer(indexer):
2904 indexer = [indexer]

/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2895 return self._engine.get_loc(casted_key)
2896 except KeyError as err:
-> 2897 raise KeyError(key) from err
2898
2899 if tolerance is not None:

KeyError: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant