大数据预测房价趋势

大数据预测房价趋势

数据挖掘步骤大概分为以下:1、数据采集2、数据清洗3、数据分析4、显示数据

还是按这4个步骤,
第一,我们用爬虫采集某网的数据,得到房价20180811.txt文件,这里是以广州城市为例。数据中有些有地铁,有些无地铁的房子,为了采集,清洗方便,这里我们选择用有地铁的房子进行统计。
数据清洗得出房价20180812.txt文件,数据以–分割,看起来更加简洁,但不可观。

String result = "";
        String filePath = "C:\\Users\\admin\\Desktop\\房价20180811.txt";
        String filePath2 = "C:\\Users\\admin\\Desktop\\房价20180812.txt";
        File file=new File(filePath);
        InputStreamReader read = new InputStreamReader(
                new FileInputStream(file),"UTF-8");
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineTxt = null;
        while((lineTxt = bufferedReader.readLine()) != null){
            //1、接受数据
            String line = lineTxt;
            //2、数据切片
            String[] fields = line.split("--");
            //凤锦苑四房两卫+1户型南北对流户型漂亮楼--42厅<i>|</i>135㎡<i>|</i>中层(共26层)<i>|</i>南北向<i>|</i>2011年建<i>|</i>--
            //碧桂园凤凰城凤锦苑--凤凰城-广园快速路(近沈海高速)</span></p><pclass="clearfixlabel"></p></dd><ddclass="price_right"><spanclass="red"><b>350</b>万</span><span>25926元/㎡</span></dd></dl><dlclass="clearfix"dataflag="bg"data-bg="{&quot;houseid&quot;:&quot;228980323&quot;,&quot;agentid&quot;:&quot;166295756&quot;,&quot;housetype&quot;:&quot;FAGT&quot;,&quot;listingtype&quot;:&quot;1,2&quot;}"id="list_D03_02"><dtclass="floatl"><aps="51_2_60"href="http://esf.gz.fang.com/chushou/3_228980323.htm"target="_blank"data_channel="1,2"><imgsrc="./【广州二手房_广州二手房出售】-广州房天下_files/loading160_120.gif"src2="http://cdnsfb.soufunimg.com/viewimage/1/2018_7/26/M13/36/14f806a3da35417db07bdbb9708a2f9f/220x165c.jpg"onerror="imgiserror(this,&#39;http://cdnsfb.soufunimg.com/1/2018_7/26/M13/36/14f806a3da35417db07bdbb9708a2f9f.jpg&#39;)"></a></dt><dd><h4class="clearfix"><aps="51_2_60"href="http://esf.gz.fang.com/chushou/3_228980323.htm"target="_blank"data_channel="1,2"title="万和苑滘口地铁站旁准电梯精装两房产权清晰带装修价格可谈"><spanclass="tit_shop">万和苑滘口地铁站旁准电梯精装两房产权清晰带装修价格可谈</span></a></h4><pclass="tel_shop">22厅<i>|</i>63㎡<i>|</i>中层(共8层)<i>|</i>东南向<i>|</i>1999年建<i>|</i><spanclass="people_name"><anofollow=""href="http://esf.gz.fang.com/a/jd18529257707"title="访问[简丹]的个人网上店铺,查看更多房源"target="_blank">简丹</a></span></p><pclass="add_shop"><atarget="_blank"href="http://esf.gz.fang.com/house-xm2811006967/"title="万和苑">万和苑</a><span>芳村-芳村兴东路17号</span></p><pclass="clearfixlabel"><spanclass="bg_noneicon_dt">距5号线滘口站约948米</span></p></dd><ddclass="price_right"><spanclass="red"><b>185</b>万</span><span>29365元/㎡</span></dd></dl><dlclass="clearfix"dataflag="bg"data-bg="{&quot;houseid&quot;:&quot;228274730&quot;,&quot;agentid&quot;:&quot;164319321&quot;,&quot;housetype&quot;:&quot;FAGT&quot;,&quot;listingtype&quot;:&quot;1,2&quot;}"id="list_D03_03"><dtclass="floatl"><aps="51_3_60"href="http://esf.gz.fang.com/chushou/3_228274730.htm"target="_blank"data_channel="1,2"><imgsrc="./【广州二手房_广州二手房出售】-广州房天下_files/loading160_120.gif"src2="http://cdnsfb.soufunimg.com/viewimage/1/2018_7/16/M19/11/74d2320fde6141dfaa9da26c03a34916/220x165c.jpg"onerror="imgiserror(this,&#39;http://cdnsfb.soufunimg.com/1/2018_7/16/M19/11/74d2320fde6141dfaa9da26c03a34916.jpg&#39;)"></a></dt><dd><h4class="clearfix"><aps="51_3_60"href="http://esf.gz.fang.com/chushou/3_228274730.htm"target="_blank"data_channel="1,2"title="主推春江花园,南向3房,21号线棠东站今年开通,送家电家私"><spanclass="tit_shop">主推春江花园,南向3房,21号线棠东站今年开通,送家电家私</span></a></h4><pclass="tel_shop">32厅<i>|</i>103㎡<i>|</i>中层(共25层)<i>|</i>南向<i>|</i>2002年建<i>|</i><spanclass="people_name"><anofollow=""href="http://esf.gz.fang.com/a/520tanning"title="访问[谭许宁]的个人网上店铺,查看更多房源"target="_blank">谭许宁</a></span></p><pclass="add_shop"><atarget="_blank"href="http://esf.gz.fang.com/house-xm2811022338/"title="春江花园">春江花园</a><span>车陂-中山大道棠东东路--
            //距4号线车陂站约687米--<b>350</b>万--33981元/㎡-
            //3、拿到关键字段
            String titleStr = fields[0];
            String houseStr = fields[1];
            String streetStr = fields[2];
            String addressStr = fields[3];
            if(addressStr.indexOf("</span>") > 0){
                addressStr = addressStr.substring(0, addressStr.indexOf("</span>"));
            }
            String subwayStr = fields[4];
            String totalStr = fields[5].replace("<b>", "").replace("</b>万", "");;
            String priceStr = fields[6].replace("元/㎡-", "");
            if(subwayStr.indexOf("距") == 0){
//              System.out.println(subwayStr);
                String subway0 = subwayStr.substring(subwayStr.indexOf("距")+1, subwayStr.indexOf("线")).replace("号", "");
                String subway1 = subwayStr.substring(subwayStr.indexOf("线")+1, subwayStr.indexOf("约"));
                String subway2 = subwayStr.substring(subwayStr.indexOf("约")+1, subwayStr.indexOf("米"));


                String[] houseStrs = houseStr.split("<i>|</i>");
//              System.out.println(houseStrs.length);
                if(houseStrs.length == 10){


                    String houseStrs0 = houseStrs[0].replace("室", ",").replace("厅", "").replace("<i>", "");
                    //              System.out.println(houseStr);
                    String[] houseStrs0s = houseStrs0.split(",");
                    String house0 = houseStrs0s[0];
                    String house1 = houseStrs0s[1];

                    String area = houseStrs[2].replace("㎡", "");
                    String flood = houseStrs[4].substring(0, 2);
                    String way = houseStrs[6];
                    String year = (2018-Integer.parseInt(houseStrs[8].replace("年建", "")))+"";
                    //4、数据输出到
                    result = titleStr+"--"+house0+"--"+house1+"--"+area+"--"+flood+"--"+way+"--"+year+
                            "--"+streetStr+"--"+addressStr+"--"+subway0+"--"+subway1+"--"+subway2+"--"+totalStr+"--"+priceStr+"\r\n";
                    //
                    _txtUtils.addTxtContent(filePath2, result);
                }}
        }
        read.close();
        System.out.println(result);

这里写图片描述

根据房子的面积大小,预测房价。虽然房价每年以指数方式增加,不符合社会进步与落后的生产力的矛盾观念,但还是学习一下用线性回归预测那一年的房价。这里只能当作参考学习。就学爬虫获取数据,这里我们有可以通过excel获取数据,从在线网页获取数据,从api中获取数据,从html文件获取数据等,获取数据后,就要对数据进行清洗,不用洗衣机,不用挖掘机,简单去重去空操作就可以。然后分析一下用什么图表显示。用直观的图形表达你的需求。

需要源码学习,下载地址:http://47.98.237.162/detail/1/174

猜你喜欢

转载自blog.csdn.net/sinat_15153911/article/details/81808251