abhishekkrthakur/approachingalmost

Page 19 Error

NakulGoswami opened this issue · 3 comments

Hi Abhishek,
I recently bought your book.
I get the following error when I ren the code that is ritten on page 19.

clf.fit(df_train[cols], df_train.quality)
AttributeError: 'list' object has no attribute 'fit'

Can you help with the accurate code?
Thanks
Nakul

Hi Abhishek,
In addition,
when I try to run the first code in the book, I get the following error.
I am sure it is somenthing simple, but do please let me know how to proceed?
Is there an updated code list for your book that you can point me to because that would be helpful.

Thanks
Nakul

TypeError Traceback (most recent call last)
TypeError: '(1, slice(None, None, None))' is an invalid key

in
15 pixel_values, targets = data
16 targets = targets.astype(int)
---> 17 single_image = pixel_values[1, :].reshape(28, 28)
18 plt.imshow(single_image, cmap='gray')
19 tsne = manifold.TSNE(n_components=2, random_state=42)
~\Anaconda3\lib\site-packages\pandas\core\frame.py in getitem(self, key)
3022 if self.columns.nlevels > 1:
3023 return self._getitem_multilevel(key)
-> 3024 indexer = self.columns.get_loc(key)
3025 if is_integer(indexer):
3026 indexer = [indexer]
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
3078 casted_key = self._maybe_cast_indexer(key)
3079 try:
-> 3080 return self._engine.get_loc(casted_key)
3081 except KeyError as err:
3082 raise KeyError(key) from err
pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

Hi Abhishek,
I recently bought your book.
I get the following error when I ren the code that is ritten on page 19.

clf.fit(df_train[cols], df_train.quality)
AttributeError: 'list' object has no attribute 'fit'

Can you help with the accurate code?
Thanks
Nakul

Hello Nakul , I fear you have not initialized the model variable clf correctly .
Can u post a pic or snippet of your code ?

Hi Abhishek, In addition, when I try to run the first code in the book, I get the following error. I am sure it is somenthing simple, but do please let me know how to proceed? Is there an updated code list for your book that you can point me to because that would be helpful.

Thanks Nakul

TypeError Traceback (most recent call last) TypeError: '(1, slice(None, None, None))' is an invalid key

in 15 pixel_values, targets = data 16 targets = targets.astype(int) ---> 17 single_image = pixel_values[1, :].reshape(28, 28) 18 plt.imshow(single_image, cmap='gray') 19 tsne = manifold.TSNE(n_components=2, random_state=42) ~\Anaconda3\lib\site-packages\pandas\core\frame.py in getitem(self, key) 3022 if self.columns.nlevels > 1: 3023 return self._getitem_multilevel(key) -> 3024 indexer = self.columns.get_loc(key) 3025 if is_integer(indexer): 3026 indexer = [indexer] ~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 3078 casted_key = self._maybe_cast_indexer(key) 3079 try: -> 3080 return self._engine.get_loc(casted_key) 3081 except KeyError as err: 3082 raise KeyError(key) from err pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

TypeError Traceback (most recent call last)
TypeError: '(1, slice(None, None, None))' is an invalid key
To solve this problem, you should to change code to "single_image = pixel_values[1, :].reshape(28, 28)" .It works