ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

ML之FE:基于LiR/Ridge/Lasso/ElasticNet/AvgModels/RF算法(GSCV) 利用某市房价数据集(特征工程处理)进行房价回归预测

2021-06-15 20:03:06  阅读:264  来源: 互联网

标签:GSCV non Ridge 房价 house object NaN 房本满 null


ML之FE:基于LiR/Ridge/Lasso/ElasticNet/AvgModels/RF算法(GSCV) 利用某市房价数据集(特征工程处理)进行房价回归预测

 

 

 

 

目录

输出结果

设计思路

核心代码


 

 

 

 

 

 

输出结果

1、输出基本信息



bj_data.info():
Int64Index: 48324 entries, 418423 to 627466
Data columns (total 22 columns):
introduction_house    48324 non-null object
community_house       48324 non-null object
href_house            48324 non-null object
unit_house            48324 non-null object
size_house            48324 non-null object
direction_house       48324 non-null object
decoration_house      48313 non-null object
elevator_house        47437 non-null object
type_house            48324 non-null object
years_house           48311 non-null object
area_house            48324 non-null object
interests_house       48324 non-null object
watch_times           48324 non-null object
submit_period         0 non-null float64
years_period          39804 non-null object
tax_free              45673 non-null object
total_price           48324 non-null float64
smeter_price          48324 non-null object
region                48324 non-null object
info_cluster          0 non-null object
info_flood            0 non-null object
info_follow           0 non-null object

bj_data.head():
 introduction_house community_house                                           href_house unit_house size_house direction_house decoration_house elevator_house type_house years_house area_house interests_house watch_times  submit_period years_period tax_free  total_price smeter_price region info_cluster info_flood info_follow
418423  长城脚下,精装修别墅,满五唯一,业主诚意出售。           清凉盛景   https://bj.lianjia.com/ershoufang/101103236018.html       5室3厅   269.93平米             南 北               精装            NaN    底层(共2层)        暂无数据       延庆其它            3人关注        0次带看            NaN          NaN    房本满五年        998.0  单价36973元/平米     bj          NaN        NaN         NaN
418424  商品房  满五年  家庭名下一套住房  环境好           清凉盛景   https://bj.lianjia.com/ershoufang/101102750912.html       4室2厅   269.93平米             南 北               精装            NaN         2层  2010年建暂无数据       延庆其它           14人关注        0次带看            NaN          NaN    房本满五年       1250.0  单价46309元/平米     bj          NaN        NaN         NaN
418425           湖南小区 2室1厅 179万           湖南小区   https://bj.lianjia.com/ershoufang/101103256056.html       2室1厅    71.45平米             南 北               其他            NaN   中楼层(共6层)  1996年建暂无数据       延庆其它            8人关注        0次带看            NaN          NaN    房本满五年        179.0  单价25053元/平米     bj          NaN        NaN         NaN
418426          清凉盛景 4室2厅 1180万           清凉盛景   https://bj.lianjia.com/ershoufang/101103166425.html       4室2厅   252.16平米             南 北               精装            NaN    底层(共2层)  2010年建暂无数据       延庆其它            0人关注        0次带看            NaN          NaN    房本满五年       1180.0  单价46796元/平米     bj          NaN        NaN         NaN
424545        君山别墅 边户独栋 391平毛坯房           君山别墅   https://bj.lianjia.com/ershoufang/101101025128.html       3室2厅   391.86平米             南 北               毛坯            NaN    底层(共2层)  2011年建暂无数据       密云其它          107人关注        1次带看            NaN        房本满两年    房本满五年       1000.0  单价25520元/平米     bj          NaN        NaN         NaN

2.2.1、处理【size_house】列

2.2.2、处理【size-interests_house】、【watch_times】、【smeter_price】列

2.2.3、处理【unit_house】列

2.2.4、处理【type_house】列

2.2.5、处理【year_house】列:

 

2.3、处理【direction_house】列

2.4、缺失值处理

Percentage of missing values
               Feature  Unique_values  Percentage of missing values  Percentage of values in the biggest category     type
21         info_follow              0                    100.000000                                    100.000000   object
13       submit_period              0                    100.000000                                    100.000000  float64
20          info_flood              0                    100.000000                                    100.000000   object
19        info_cluster              0                    100.000000                                    100.000000   object
14        years_period              1                     17.630991                                     82.369009   object
15            tax_free              1                      5.485887                                     94.514113   object
7       elevator_house              6                      1.835527                                     62.018873   object
9          years_house            210                      0.026902                                      3.186822   object
6     decoration_house             15                      0.022763                                     49.163976   object
18              region              1                      0.000000                                    100.000000   object
17        smeter_price          35405                      0.000000                                      0.066220   object
16         total_price           1804                      0.000000                                      1.338879  float64
0   introduction_house          47779                      0.000000                                      0.014486   object
12         watch_times             93                      0.000000                                     33.451287   object
1      community_house           5674                      0.000000                                      0.360070   object
10          area_house            235                      0.000000                                      3.029551   object
8           type_house            291                      0.000000                                      8.718235   object
5      direction_house            207                      0.000000                                     45.348067   object
4           size_house          15283                      0.000000                                      0.091052   object
3           unit_house             79                      0.000000                                     36.845046   object
2           href_house          48323                      0.000000                                      0.004139   object
11     interests_house            638                      0.000000                                      2.460475   object

bj_data.shape():after drop 
(48324, 14)

bj_data.head():after drop
       unit_house size_house direction_house decoration_house elevator_house type_house years_house area_house interests_house watch_times years_period tax_free  total_price smeter_price
418423       5室3厅   269.93平米             南 北               精装            NaN    底层(共2层)        暂无数据       延庆其它            3人关注        0次带看          NaN    房本满五年        998.0  单价36973元/平米
418424       4室2厅   269.93平米             南 北               精装            NaN         2层  2010年建暂无数据       延庆其它           14人关注        0次带看          NaN    房本满五年       1250.0  单价46309元/平米
418425       2室1厅    71.45平米             南 北               其他            NaN   中楼层(共6层)  1996年建暂无数据       延庆其它            8人关注        0次带看          NaN    房本满五年        179.0  单价25053元/平米
418426       4室2厅   252.16平米             南 北               精装            NaN    底层(共2层)  2010年建暂无数据       延庆其它            0人关注        0次带看          NaN    房本满五年       1180.0  单价46796元/平米
424545       3室2厅   391.86平米             南 北               毛坯            NaN    底层(共2层)  2011年建暂无数据       密云其它          107人关注        1次带看        房本满两年    房本满五年       1000.0  单价25520元/平米

bj_data.head():【size_house】drop+numerical
结果:
 ········
total_price         48324 non-null float64
smeter_price        48324 non-null object
dtypes: float64(2), object(12)
memory usage: 5.5+ MB
None
       unit_house  size_house1 direction_house decoration_house elevator_house type_house years_house area_house interests_house watch_times years_period tax_free  total_price smeter_price
418423       5室3厅       269.93             南 北               精装            NaN    底层(共2层)        暂无数据       延庆其它            3人关注        0次带看          NaN    房本满五年        998.0  单价36973元/平米
418424       4室2厅       269.93             南 北               精装            NaN         2层  2010年建暂无数据       延庆其它           14人关注        0次带看          NaN    房本满五年       1250.0  单价46309元/平米
418425       2室1厅        71.45             南 北               其他            NaN   中楼层(共6层)  1996年建暂无数据       延庆其它            8人关注        0次带看          NaN    房本满五年        179.0  单价25053元/平米
418426       4室2厅       252.16             南 北               精装            NaN    底层(共2层)  2010年建暂无数据       延庆其它            0人关注        0次带看          NaN    房本满五年       1180.0  单价46796元/平米
424545       3室2厅       391.86             南 北               毛坯            NaN    底层(共2层)  2011年建暂无数据       密云其它          107人关注        1次带看        房本满两年    房本满五年       1000.0  单价25520元/平米

bj_data.head():【interests_house】、【watch_times】、【smeter_price】, Regularization
结果:
····
 unit_house  size_house1  smeter_price1  watch_times1  interests_house1 direction_house decoration_house elevator_house type_house years_house area_house years_period tax_free  total_price
418423       5室3厅       269.93          36973             0                 3             南 北               精装            NaN    底层(共2层)        暂无数据       延庆其它          NaN    房本满五年        998.0
418424       4室2厅       269.93          46309             0                14             南 北               精装            NaN         2层  2010年建暂无数据       延庆其它          NaN    房本满五年       1250.0
418425       2室1厅        71.45          25053             0                 8             南 北               其他            NaN   中楼层(共6层)  1996年建暂无数据       延庆其它          NaN    房本满五年        179.0
418426       4室2厅       252.16          46796             0                 0             南 北               精装            NaN    底层(共2层)  2010年建暂无数据       延庆其它          NaN    房本满五年       1180.0
424545       3室2厅       391.86          25520             1               107             南 北               毛坯            NaN    底层(共2层)  2011年建暂无数据       密云其它        房本满两年    房本满五年       1000.0

bj_data.head():【unit_house】, structure new features
结果·······
 size_house1  rooms  living_room  bedroom  smeter_price1  watch_times1  interests_house1 direction_house decoration_house elevator_house type_house years_house area_house years_period tax_free  total_price
418423       269.93    8.0          3.0      5.0          36973             0                 3             南 北               精装            NaN    底层(共2层)        暂无数据       延庆其它          NaN    房本满五年        998.0
418424       269.93    6.0          2.0      4.0          46309             0                14             南 北               精装            NaN         2层  2010年建暂无数据       延庆其它          NaN    房本满五年       1250.0
418425        71.45    3.0          1.0      2.0          25053             0                 8             南 北               其他            NaN   中楼层(共6层)  1996年建暂无数据       延庆其它          NaN    房本满五年        179.0
418426       252.16    6.0          2.0      4.0          46796             0                 0             南 北               精装            NaN    底层(共2层)  2010年建暂无数据       延庆其它          NaN    房本满五年       1180.0
424545       391.86    5.0          2.0      3.0  

 

设计思路

核心代码

from sklearn.base import BaseEstimator, TransformerMixin, RegressorMixin, clone

class AveragingModels(BaseEstimator, TransformerMixin, RegressorMixin): 
    def __init__(self, models):
        self.models = models
        
    def fit(self, X, y):
        self.models_ = [clone(x) for x in self.models]
        
        # Train cloned base models
        for model in self.models_:
            model.fit(X, y)

        return self

    def predict(self, X):
        predictions = np.column_stack([
            model.predict(X) for model in self.models_ ])
        return np.mean(predictions, axis=1) 

Averaged_models = AveragingModels(models = (LiR_model, Ridge_model, Lasso_model, ElasticNet_model))          
Averaged_models_score = rmse_cv(Averaged_models, X, y)     


param_grid2 = {'max_depth': range(30, 60, 5), 'min_samples_split':range(2, 11, 1)}
gs2 = GridSearchCV(estimator=gs1.best_estimator_, param_grid=param_grid2, scoring='neg_mean_squared_error', cv=3, verbose=0)
gs2.fit(X_train, y_train)


param_grid3 = {'max_features': range(10, 250, 8)}
gs3 = GridSearchCV(estimator=gs2.best_estimator_, param_grid=param_grid3, scoring='neg_mean_squared_error', cv=3, verbose=0)
gs3.fit(X_train, y_train)
                                        

 

 

 

标签:GSCV,non,Ridge,房价,house,object,NaN,房本满,null
来源: https://blog.51cto.com/u_14217737/2905676

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有