Key error when i try to compute final theta and error_list

I am gettign this error when ever I try to compute the final theta
KeyError Traceback (most recent call last)
K:\ANACONDA\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2656 try:
-> 2657 return self._engine.get_loc(key)
2658 except KeyError:

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()

Hi @Shubhankit-Tiwari-1738649599558824,
Can you please share your code on online ide? also please share the screenshot of the error, it would be easier for me to check directly that piece of code which is causing the error.

@Shubhankit-Tiwari-1738649599558824
Please upload you code as well on https://ide.codingblocks.com and share the link


this is the code

Hi,
I would like to point some of the mistakes you did:

  • You forgot to convert the data frame into numpy array using .values that’s why this error is coming. Use this x=dfx.values y=dfy.values
  • After this error resolved, in the gradient function you were calculating hypothesis outside the for loop, which is wrong since we want to calculate it for every example of the dataset. Also, you didn’t declare the var. m
  • Use a smaller learning rate - 0.0001

Here is the updated code for your reference

I hope now you can solve the problem well.
Thanks :slight_smile:

1 Like

Thanks for resolving my problem :slightly_smiling_face: