华盛顿大学机器学习基础:案例研究week2

利用Python学习简单的数据操作

import graphlab
sales = graphlab.SFrame('home_data.gl/')
#exploring the data for housing sales
graphlab.canvas.set_target('ipynb')
sales.show(view="Scatter Plot",x="sqft_living",y="price")

这里写图片描述

#create a simple regression model of sqft_living to price
train_data,test_data = sales.random_split(.8,seed =0)
#build the regression model
sqft_model = graphlab.linear_regression.create(train_data,target="price",features=['sqft_living'])

这里写图片描述

print(test_data['price'].mean())
print(sqft_model.evaluate(test_data))

这里写图片描述

# let's show what our predictions look like
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(test_data['sqft_living'],test_data['price'],'.',       test_data['sqft_living'],sqft_model.predict(test_data),'-')

这里写图片描述

sqft_model.get('coefficients')

这里写图片描述

# explore other features in the data
my_features=['bedrooms','bathrooms','sqft_living','sqft_lot','floors','zipcode']
sales[my_features].show()

这里写图片描述

sales.show(view='BoxWhisker Plot',x='zipcode',y='price')

这里写图片描述

# build a regression model with more features
my_features_model = graphlab.regression.create(train_data,target='price',features=my_features)

这里写图片描述

print(sqft_model.evaluate(test_data))
print(my_features_model.evaluate(test_data))

这里写图片描述

# apply learned models to predict prices of 3 houses
house1 = sales[sales['id']=='5309101200']

这里写图片描述

<img src="rich.jpeg">#这个语句要写在esc+M下才能出现图片

这里写图片描述

这里写图片描述

# prediction for a second, fancier house
house2 = sales[sales['id']=='1925069082']

这里写图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值