DAY 10
0
AI & Machine Learning

## Inspecting the model coefficients learned

``````sqft_model.get('coefficients')
``````
name index value stderr
(intercept) None -43814.8902666 5047.42632188
sqft_living None 280.360245938 2.21700145099

• 截距：直線與x相交的地方
• 斜率：單位面積的價格，每一平方要花多少錢

## Exploring other features of the data

``````#將要新增的特徵，新增到list當中
my_features = ['bedrooms','bathrooms','sqft_living','sqft_lot','floors','zipcode']
sales[my_features].show
``````

• 大部份的房子都是三間臥室
• 至於浴室在美國有個有特殊的規定，如果是套房的浴室算1個、不在套房內的(不含淋浴設備)算0.5個、如果是不再套房內的浴室(有淋浴沒浴缸)算0.75個(到底是三小= =)
• 大部份房子都是一層樓

``````#BoxWhisker Plot將會顯示兩個特徵之間的關係
#我想看看門牌與價格的關聯(我曾聽說掛上中正區的門牌50萬起跳、明明萬華就在隔壁)
sales.show(view='BoxWhisker Plot',x='zipcode',y='price')
``````

## Learning a model to predict house prices from more features

``````my_features_model = graphlab.linear_regression.create(train_data,target='price',features=my_features)
``````

``````print sqft_model.evaluate(test_data)
# {'max_error': 4142275.367360657, 'rmse': 255188.09204898693}
print my_features_model.evaluate(test_data)
# {'max_error': 3500449.806693536, 'rmse': 179356.3725536438}
``````

## Applying learned models to predict price of an average house

``````house1 = sales[sales['id'] == '5309101200']
# price:620000
``````
id date price bedrooms bathrooms sqft_living sqft_lot floors view condition grade sqft_above sqft_basement yr_built yr_renovated zipcode lat long sqft_living15 sqft_lot15
5309101200 2014-06-05 00:00:00+00:00 620000 4 2.25 2400 5350 1.5 0 4 7 1460 940 1929 0 98117 47.67632376 -122.37010126 1250.0 4880.0

``````print sqft_model.predict(house1)
# [630004.8234759354]
print my_features_model.predict(house1)
# [720058.291038626]
``````

## Applying learned models to predict price of two fancy houses

``````house2 = sales[sales['id'] == '1925069082']
# price:2200000
``````
id date price bedrooms bathrooms sqft_living sqft_lot floors view condition grade sqft_above sqft_basement yr_built yr_renovated zipcode lat long sqft_living15 sqft_lot15
1925069082 2015-05-11 00:00:00+00:00 2200000 5 4.25 4640 22703 2 4 5 8 2860 1780 1952 0 98052 47.63925783 -122.09722322 3140.0 14200.0

``````print sqft_model.predict(house2)
[1261846.2617304123]

print my_features_model.predict(house2)
# [720058.291038626]
[1451243.0229620067]
``````

## 後記

markdown table editor 顧名思義，幫你自動產生語法表格的好物