1. 程式人生 > >華盛頓大學機器學習基礎:案例研究week2

華盛頓大學機器學習基礎:案例研究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']

這裡寫圖片描述