I am currently doing a course i Machine Learning from Coursera ( https://www.coursera.org/learn/ml-foundations/lecture/6wD6H/visualizing-predictions-of-simple-model-with-matplotlib ). The course use Graphlab Create framework for during the course for learning and assignments. I don't want to use Graphlab
, instead I am using pandas
, numpy
for assignments.
In the course, the instructor has created a regression model, and then he shows the prediction using matplotlib
:
Build Regression Model
sqft_model = graphlab.linear_regression.create(train_data, target='price', features=['sqft_living'],validation_set=None)
and then the prediction code is as follows:
plt.plot(test_data['sqft_living'],test_data['price'],'.',
test_data['sqft_living'],sqft_model.predict(test_data),'-')
The result is:
In the above image, blue dots are test data, green line is the prediction from the simple regression.
I am a complete beginner to programming and python. I wanted to use free resources such as pandas and scikit
. I have used following to do the same in Ipython
:
Build Regression Model
from pandas.stats.api import ols
sqft_model = ols(y=train_data['price'], x=train_data['sqft_living'])
But, I get the following error while inputting the prediction code:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
Thus, I am not able to produce the desired result as done by the instructor (i.e. the image shown above). Can anyone help me out?
pls find the below link to download data: