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

Getting KeyError: 'Decision' #32

Closed
zed1025 opened this issue Nov 1, 2022 · 1 comment
Closed

Getting KeyError: 'Decision' #32

zed1025 opened this issue Nov 1, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@zed1025
Copy link

zed1025 commented Nov 1, 2022

Trying to find gain using for SepalLengthCm in IRIS dataset following this .

config = {'algorithm': 'ID3'}
sorted(df['SepalLengthCm'].unique())

threshold = 6.0
idx = df[df['SepalLengthCm'] <= threshold].index
tmp_df = df.copy()
tmp_df['SepalLengthCm'] = '>'+str(threshold)
tmp_df.loc[idx, 'SepalLengthCm'] = '<='+str(threshold)

gain = Training.findGains(tmp_df, config)
print(threshold, ': ', gain)

Also

df = iris[['SepalLengthCm', 'y']]

When running this I get the following error

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File D:\Files\dev\misc\py_venvs\cvip\lib\site-packages\pandas\core\indexes\base.py:3621, in Index.get_loc(self, key, method, tolerance)
   3620 try:
-> 3621     return self._engine.get_loc(casted_key)
   3622 except KeyError as err:

File D:\Files\dev\misc\py_venvs\cvip\lib\site-packages\pandas\_libs\index.pyx:136, in pandas._libs.index.IndexEngine.get_loc()

File D:\Files\dev\misc\py_venvs\cvip\lib\site-packages\pandas\_libs\index.pyx:163, in pandas._libs.index.IndexEngine.get_loc()

File pandas\_libs\hashtable_class_helper.pxi:5198, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas\_libs\hashtable_class_helper.pxi:5206, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'Decision'

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

KeyError                                  Traceback (most recent call last)
Input In [10], in <cell line: 7>()
      4 tmp_df['SepalLengthCm'] = '>'+str(threshold)
      5 tmp_df.loc[idx, 'SepalLengthCm'] = '<='+str(threshold)
----> 7 gain = Training.findGains(tmp_df, config)
      8 print(threshold, ': ', gain)

File D:\Files\dev\misc\py_venvs\cvip\lib\site-packages\chefboost\training\Training.py:107, in findGains(df, config)
    104 def findGains(df, config):
    106 	algorithm = config['algorithm']
--> 107 	decision_classes = df["Decision"].unique()
    109 	#-----------------------------
    111 	entropy = 0

File D:\Files\dev\misc\py_venvs\cvip\lib\site-packages\pandas\core\frame.py:3505, in DataFrame.__getitem__(self, key)
   3503 if self.columns.nlevels > 1:
   3504     return self._getitem_multilevel(key)
-> 3505 indexer = self.columns.get_loc(key)
   3506 if is_integer(indexer):
   3507     indexer = [indexer]

File D:\Files\dev\misc\py_venvs\cvip\lib\site-packages\pandas\core\indexes\base.py:3623, in Index.get_loc(self, key, method, tolerance)
   3621     return self._engine.get_loc(casted_key)
   3622 except KeyError as err:
-> 3623     raise KeyError(key) from err
   3624 except TypeError:
   3625     # If we have a listlike key, _check_indexing_error will raise
   3626     #  InvalidIndexError. Otherwise we fall through and re-raise
   3627     #  the TypeError.
   3628     self._check_indexing_error(key)

KeyError: 'Decision'
@serengil serengil added the bug Something isn't working label Nov 1, 2022
@serengil
Copy link
Owner

Closed with PR - #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants