Forum

Notifications
Clear all

SUP 2 KNN  

   RSS

0

I am currently at exercise 2 for classification using KNN. 

when i execute the code

features = ['OverallQual','SalePrice']
data = input_data[features].sample(n=10, random_state=42)
data.columns = ['X','Y'] # rename the columns to make it easier to reference

I encounter these errors, please help thanks 

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
 in 
      1 features = ['OverallQual','SalePrice']
----> 2 data = input_data[features].sample(n=10, random_state=42)
      3 data.columns = ['X','Y'] # rename the columns to make it easier to reference

D:\Python\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
   2804             if is_iterator(key):
   2805                 key = list(key)
-> 2806             indexer = self.loc._get_listlike_indexer(key, axis=1, raise_missing=True)[1]
   2807 
   2808         # take() does not accept boolean indexers

D:\Python\lib\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis, raise_missing)
   1550 
   1551         self._validate_read_indexer(
-> 1552             keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
   1553         )
   1554         return keyarr, indexer

D:\Python\lib\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing)
   1643             if not (self.name == "loc" and not raise_missing):
   1644                 not_found = list(set(key) - set(ax))
-> 1645                 raise KeyError(f"{not_found} not in index")
   1646 
   1647             # we skip the warning on Categorical/Interval

KeyError: "['SalePrice'] not in index"
1 Answer
0

Hi @zenchong!

Have you downloaded and loaded in the data properly from https://www.kaggle.com/c/home-data-for-ml-course/overview ? Did you run all the cells from the first cell in the notebook?

You may want to join the chat in our Discord server at https://discord.gg/ANrz2Vz  to more easily share about your error and get quick replies.

This post was modified 1 month ago by Yi Sheng
Share:

Delete your account