Test and train Kaggle datasets

Hi team,

The code you have provided is working on train data set and giving me good accuracy. Now if I use the theta obtained from the training dataset and using it for test to predict the output and calculate the r2 score then I am facing issue with the calculation of r2 since test and train has different shape and hence test data is throwing error stating broadcasting of array values are not possible. Kindly help me through the code so that a generic linear regression with multivariate can be used on more Kaggle dataset.

Hey @karthik95abi, can you please share your ipynb by uploading it on google drive and sharing the link here.

Hi Vasu,

I am sharing my google colab notebook itself

https://colab.research.google.com/drive/13cW9B6QdiLqc6uNbSBLlKxqakYOIFNzc

Hey @karthik95abi, your code was completely fine, but there was one single error since you are using vectorization method you should
y_train = y_train.reshape((-1,1))
y_test = y_test.reshape((-1,1))

And than your code will run completely fine.
Hope this cleared your doubt. :blush:
Plz mark the doubt as resolved in my doubts section. :sunny:

Thank you vasu gupta. But I need some more clarification on how does it work. I mean the shape becomes (7,1) but how does it change the theta value with which it is getting multiplied.

Hey @karthik95abi, actually this problem arises when you perform arithmetic operation on two arrays like
you use ar3 = ar1 + ar2, and now ar1 is of shape (10,1) and ar2 is of shape (10,). Now you expect ar3 to be of shape (10,1) but actually it becomes (10,10). And hence we need to reshape ar2.

In the code the problem arises whenever you are using y_-y

Hope now your doubt is resolved.
Plz mark it as resolved in my doubts section. :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.