波士頓房價預測

      在〈波士頓房價預測〉中尚無留言

波士頓房價預測

機器學習與深度學習

深度學習是屬於機器學習其中一個分支,深度學習不需要輸入特徵,會自已去找特徵。

不過此房價預測範例必需輸入特徵,所以不屬於深度學習範圍。那為何把此專案例入深度學習呢??

在此必需承認一件事,前面的 AI人工智慧 章節混合了 “非深度學習” 及 “深度學習” 的課程。如今新增了深度學習的課程,所以必需強加區隔。在以往的 AI人工智慧 並未介紹如何由特徵進行分析,所以由此開始介紹。

波士頓房價預測

盡管我們對房價不是那麼的關心 (就買不起咩),更何況這是波士頓的房價狀況。但這一道題目是許多機器學習者的起手式,介紹了資料處理的詳細步驟,所以必需耐心理解。

心理準備

每個人都希望藉由 AI 來精準預測結果,這是外行人的想法,說的更難聽一點,這是腦殘人的想法。

房價會依賣方的心情(吸毒急需錢,戰爭要移民……..),買方的心情(財力,需求…….),通膨,物價指數,有上千萬種因素。而且房價不是用斤兩來秤的,也不是一斤多少錢有絕對的標準,所以別再問為什麼預測的房價不一樣(或不準),因為這只是一個大略的範圍而以。

安裝套件

請先安裝如下套件。

pip install scikit-learn matplotlib seaborn

載入資料

波士頓房價資料請由本網站下載 : boston.xlsx。然後使用如下代碼載入資料

import pandas as pd
display=pd.options.display
display.max_columns=None
display.max_rows=None
display.width=None
display.max_colwidth=None
df=pd.read_excel("boston.xlsx", sheet_name='Sheet1',index_col=0, keep_default_na=False)
print(df)

結果如下

     PRICE      CRIM     ZN  INDUS  CHAS     NOX     RM    AGE      DIS   RAD    TAX  PTRATIO       B  LSTAT
0     24.0   0.00632   18.0   2.31   0.0  0.5380  6.575   65.2   4.0900   1.0  296.0     15.3  396.90   4.98
1     21.6   0.02731    0.0   7.07   0.0  0.4690  6.421   78.9   4.9671   2.0  242.0     17.8  396.90   9.14
2     34.7   0.02729    0.0   7.07   0.0  0.4690  7.185   61.1   4.9671   2.0  242.0     17.8  392.83   4.03
3     33.4   0.03237    0.0   2.18   0.0  0.4580  6.998   45.8   6.0622   3.0  222.0     18.7  394.63   2.94
4     36.2   0.06905    0.0   2.18   0.0  0.4580  7.147   54.2   6.0622   3.0  222.0     18.7  396.90   5.33
5     28.7   0.02985    0.0   2.18   0.0  0.4580  6.430   58.7   6.0622   3.0  222.0     18.7  394.12   5.21
....................................

共有506筆資料,13個特徵。PRICE 為房價,RM 為每棟房子的房間數,LSTAT(中低收入戶在此處的人口比例)。詳細欄位說明如下

CRIM     per capita crime rate by town
ZN       proportion of residential land zoned for lots over 25,000 sq.ft.
INDUS    proportion of non-retail business acres per town
CHAS     Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)
NOX      nitric oxides concentration (parts per 10 million)
RM       average number of rooms per dwelling
AGE      proportion of owner-occupied units built prior to 1940
DIS      weighted distances to five Boston employment centres
RAD      index of accessibility to radial highways
TAX      full-value property-tax rate per $10,000
PTRATIO  pupil-teacher ratio by town
B        1000(Bk - 0.63)^2 where Bk is the proportion of black people by town
LSTAT    % lower status of the population
MEDV     Median value of owner-occupied homes in $1000's   

EDA(Explorator Data Analysis)

資料分析探索 (Explorator Data Analysis) 是讓我們對收集到的資料有充分的了解。包含了
房價分佈 : 每個房價的分佈圖
相關特徵 : 那些事情 (特徵) 對房價的影響特別力害,
無關特徵 : 那些事情 (特徵) 對房價沒啥影響。

房價分佈

底下使用 sns顯示 df[‘PRICE’] ,也就是顯示每一間房屋的價格分佈

🔒 更多內容,請登入會員繼續閱讀。

立即登入

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *