Quantcast
Channel: LinearRegression model gives me keyError 0 - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Suraj Shourie for LinearRegression model gives me keyError 0

$
0
0

As the traceback mentions, the error originates from print("Actual value of the house: ", y_test[0]).

y_test[0] will only work when randomly 20% of the data also has the 0th index in it after train_test_split. That's why it works for some values of random_state and not for most.

Generally you want to use either:

y_test.to_list()[0]y_test.iloc[0]

TLDR: Replace y_test[0] in your print stament


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>