机器学习项目实战(五) 住房价格预测
機器學習項目實戰(zhàn)系列? ?住房價格預測
目錄
機器學習項目實戰(zhàn)系列? ?住房價格預測
一、概述
二、分析數(shù)據(jù)
1.數(shù)據(jù)導入
2.基礎統(tǒng)計運算
3.特征觀察
4.建立模型
5.分析模型表現(xiàn)
(1)學習曲線
(2)復雜度曲線
6.擬合模型
7.預測銷售價格
一、概述
數(shù)據(jù)集包含波士頓剩余區(qū)域的房價,房子的費用根據(jù)犯罪率,房間數(shù)量等各種因素而變化。
房屋價格預測數(shù)據(jù)集 https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html
CRIM “numeric” 人均犯罪率
ZN “numeric” 超過2W5平方英尺的住宅用地所占比例
INDUS “numeric” 城市非零售業(yè)的商業(yè)用地比例
CHAS “integer” Charles河是否流經(jīng)
NOX “numeric” 一氧化碳濃度
RM “numeric” 每棟住宅的平均房間數(shù)
AGE “numeric” 1940年以前建成的自住房比例
DIS “numeric” 到波士頓五個中心區(qū)域的加權平均距離
RAD “integer” 到達高速公路的便利指數(shù)
TAX “numeric” 每1W美元的全值財產(chǎn)稅率
PIRATIO “numeric” 師生比
B “numeric” BK是黑人比例,越接近0.63越小,B=1000*(BK-0.63)^2
LSTAT “numeric” 低收入人口比例
MEDV “numeric” 自住房屋房價的平均房價單位為(1W美元)
二、分析數(shù)據(jù)
1.數(shù)據(jù)導入
2.基礎統(tǒng)計運算
3.特征觀察
- RM 是該地區(qū)中每個房屋的平均房間數(shù)量
- LSTAT 是指該地區(qū)有多少百分比的業(yè)主屬于是低收入階層(有工作但收入微薄)
- PTRATIO 是該地區(qū)的中學和小學里,學生和老師的數(shù)目比(學生/老師)
4.建立模型
5.分析模型表現(xiàn)
(1)學習曲線
vs.ModelLearning(features, prices)(2)復雜度曲線
6.擬合模型
from sklearn.tree import DecisionTreeRegressor from sklearn.metrics import make_scorer from sklearn.model_selection import GridSearchCVdef fit_model(X, y):""" Performs grid search over the 'max_depth' parameter for a decision tree regressor trained on the input data [X, y]. """# Create cross-validation sets from the training data# sklearn version 0.18: ShuffleSplit(n_splits=10, test_size=0.1, train_size=None, random_state=None)# sklearn versiin 0.17: ShuffleSplit(n, n_iter=10, test_size=0.1, train_size=None, random_state=None)cv_sets = ShuffleSplit(n_splits=10, test_size=0.20, random_state=42)# TODO: Create a decision tree regressor objectregressor = DecisionTreeRegressor()# TODO: Create a dictionary for the parameter 'max_depth' with a range from 1 to 10params = {'max_depth': range(1,11)}# TODO: Transform 'performance_metric' into a scoring function using 'make_scorer' scoring_fnc = make_scorer(performance_metric)# TODO: Create the grid search cv object --> GridSearchCV()# Make sure to include the right parameters in the object:# (estimator, param_grid, scoring, cv) which have values 'regressor', 'params', 'scoring_fnc', and 'cv_sets' respectively.grid = GridSearchCV(regressor, params, scoring=scoring_fnc, cv=cv_sets)# Fit the grid search object to the data to compute the optimal modelgrid = grid.fit(X, y)# Return the optimal model after fitting the datareturn grid.best_estimator_擬合模型的最優(yōu)深度是多少
7.預測銷售價格
?
?
總結
以上是生活随笔為你收集整理的机器学习项目实战(五) 住房价格预测的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tushare实战LSTM实现黄金价格预
- 下一篇: 个人实践,B450锐龙3600安装原版w