In [ ]:
import graphlab
In [47]:
sales = graphlab.SFrame('home_data.gl/')
sales.save('home_sales.csv', format='csv')
In [20]:
sales
Out[20]:
In [22]:
#graphlab.canvas.set_target('ipynb')
graphlab.canvas.set_target('browser')
sales.show(view="Scatter Plot", x="sqft_living", y="price")
In [26]:
training_data, test_data = sales.random_split(.8, seed=0)
In [27]:
sqft_model = graphlab.linear_regression.create(training_data, target='price', features=['sqft_living'])
In [28]:
print test_data['price'].mean()
In [30]:
print sqft_model.evaluate(test_data)
In [34]:
import matplotlib.pyplot as plt
%matplotlib inline
In [38]:
plt.plot(test_data['sqft_living'], test_data['price'], '.', test_data['sqft_living'], sqft_model.predict(test_data), '-')
Out[38]:
In [39]:
sqft_model.coefficients
Out[39]:
In [42]:
my_features = ['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'zipcode']
In [44]:
sales[my_features].show()
In [46]:
sales.show(view='BoxWhisker Plog', x='zipcode', y='price')
In [48]:
my_features_model = graphlab.linear_regression.create(training_data, target='price', features=my_features)
In [51]:
print sqft_model.evaluate(test_data)
print my_features_model.evaluate(test_data)
In [52]:
house1 = sales[sales['id']=='5309101200']
In [53]:
house1
Out[53]:
In [62]:
print house1['price']
print sqft_model.predict(house1)
print my_features_model.predict(house1)
In [63]:
house2 = sales[sales['id']=='1925069082']
In [64]:
house2
Out[64]:
In [68]:
print house2['price']
print sqft_model.predict(house2)
print my_features_model.predict(house2)
In [69]:
bill_gates = {'bedrooms':[8],
'bathrooms':[25],
'sqft_living':[50000],
'sqft_lot':[225000],
'floors':[4],
'zipcode':['98039'],
'condition':[10],
'grade':[10],
'waterfront':[1],
'view':[4],
'sqft_above':[37500],
'sqft_basement':[12500],
'yr_built':[1994],
'yr_renovated':[2010],
'lat':[47.627606],
'long':[-122.242054],
'sqft_living15':[5000],
'sqft_lot15':[40000]}
In [72]:
print sqft_model.predict(graphlab.SFrame(bill_gates))
print my_features_model.predict(graphlab.SFrame(bill_gates))
In [ ]: