diff --git a/PriceSystem/sell_price/zhuge0118A.py b/PriceSystem/sell_price/zhuge0118A.py index 4994de6..536a7ba 100644 --- a/PriceSystem/sell_price/zhuge0118A.py +++ b/PriceSystem/sell_price/zhuge0118A.py @@ -745,7 +745,9 @@ def commonprice(ct, rl, p,weekend): return cc1 else: return cc1 - + + #在同一个小区里,可能同时有别墅和普通住宅两种房源 + #本函数就是根据本小区的物业类型提取房源 @timer def consider_villa(ct, rl, p): @@ -776,7 +778,7 @@ def commonprice(ct, rl, p,weekend): return df else: return df - + #本函数用于判断本小区是否是别墅,并提取别墅在DataFrame 中的index def fetch_villa_index(dd): # dd=dd.dropna() @@ -801,6 +803,7 @@ def commonprice(ct, rl, p,weekend): return villa + #本函数就是提取进6个月以来某个小区第三方均价最新的一条 def dsfjujia(ct, rl, lk): query = {"city": ct, "region": rl, @@ -855,7 +858,7 @@ def commonprice(ct, rl, p,weekend): aa_zz=set(junjia.index) jiaji_lz= list(ll_zz & aa_zz) """ - + #聚类算法 def k_means_clus(pp1, clus): from sklearn.cluster import KMeans @@ -879,6 +882,11 @@ def commonprice(ct, rl, p,weekend): else: return int(pp1.mean()) + #判断两个群体是否可以协商出一个可行的价格 + #junjia_lzf群体1 + #junjia_anst,群体2 + # ctr控制参数 + #per控制百分比 def group(junjia_lzf, junjia_anst, ctr,per): bb = [] @@ -904,7 +912,7 @@ def commonprice(ct, rl, p,weekend): bb.append([someprice, numb]) ###print('bb=',bb) return bb - + #两个群体是否可以协调出最优价格 def middle_operate(junjia_lzf, junjia_anst): # #####print('%%%',ppd3['total_price']) @@ -962,7 +970,7 @@ def commonprice(ct, rl, p,weekend): return aa1_6.iloc[0] else: return None - + #把第三方均价分成两个群体 def devide_group(al, bl, junjia): alls = set(junjia.index) @@ -977,7 +985,9 @@ def commonprice(ct, rl, p,weekend): anst = set_div(bl, alls) return lzf, anst - + #本函数通过输入第三方均价和周边价格来计算小区均价 + #junjia 是一个Series index 是网站的名称 + #neighb 是周边小区的价格 def dglg_out1(junjia, neighb): """ @@ -987,13 +997,14 @@ def commonprice(ct, rl, p,weekend): 'yungujia_esf_price','fanggugu_esf_price' ] """ - + #优质的样本源 al = [ 'lianjia_esf_price', 'zhugezhaofang_esf_price', 'fanggugu_esf_price', 'yungujia_esf_price' ] + #一般的样本源 bl = ['anjuke_esf_price', 'soufang_esf_price', 'tuboshi_esf_price', @@ -1002,6 +1013,7 @@ def commonprice(ct, rl, p,weekend): ] mmax=junjia.max() + #次函数已经放弃采用 def junjia_max(mmax,dg12): if dg12!=None and mmax!=None: @@ -1020,7 +1032,7 @@ def commonprice(ct, rl, p,weekend): # ppd3dp=ppd3['total_price'].dropna() if type(neighb) != str and neighb != None: - + #参考周边对junjia进行预处理 def cut_junjia(junjia,neighb): if len(junjia)>3: @@ -1034,6 +1046,7 @@ def commonprice(ct, rl, p,weekend): junjia_lzf=junjia[al].dropna() junjia_anst=junjia[bl].dropna() ''' + #对junjia 分成两个group alldi = devide_group(al, bl, junjia) junjia_lzf = alldi[0] @@ -1133,6 +1146,8 @@ def commonprice(ct, rl, p,weekend): #赶集和安居客几乎相同并且和其他数据不同,就drop赶集网 的均价 judp=drop_ganji(junjia) + + #通过第三方均价计算小区均价 dglg = dglg_out1(judp, neighb[0]) print('dglg=',dglg) # dggg=dglg_out1(junjia,neighb[0]) @@ -1141,6 +1156,7 @@ def commonprice(ct, rl, p,weekend): # #####print('dggg=',dggg) #tt=time.time() + #通过物业类型对房源进行分类 data = consider_villa(ct, rl, p) #data.to_excel('data.xls') @@ -1151,10 +1167,11 @@ def commonprice(ct, rl, p,weekend): ####################################################### ##print('rrrr') ##print(data.shape[0]) + #增加优质样本的权重 data=add_weight(data) ##print('data=',data) if data.shape[0] > 3: - + paa = add_block(data) ppd = paa[['total_price', 'area', 'region', 'district_name', 'url', 'block', 'p_date']] # #####print('ppd##############') @@ -1170,7 +1187,9 @@ def commonprice(ct, rl, p,weekend): #ppd1[['total_price','area']].to_excel('ppd1.xls') ppd1['total_price'] = ppd1['total_price'] / ppd1['area'] - + #提取某个小区的区域价格 + #一般情况下,用周边的价格对房源进行预处理,过滤那些极小值 + #但有时候周边价格计算不出来,就需要用区域价格进行过滤 def take_region_price(ct,rl): @@ -1189,7 +1208,8 @@ def commonprice(ct, rl, p,weekend): return -1 if ppd1.shape[0] > 0: - + + #通过周边价格或区域价格对房源进行过滤 def guolv_data(ppd2, neighb): if type(neighb) is not str: ph = ppd2[ppd2['total_price'] > 0.7 * neighb] @@ -1267,13 +1287,19 @@ def commonprice(ct, rl, p,weekend): return -2, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size else: return -2,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + + #在计算均价时,同是参考第三方均价计算出的价格和房源价格 + #dglg:第三方均价计算出的价格 def map_time_price(junjia,dglg,ppd3): day_15=front_step_time(weekend,15) day_30=front_step_time(weekend,30) day_60=front_step_time(weekend,60) + #考虑最近15天的房价和dglg price_15= consider_time_ss1(junjia,dglg,ppd3,day_15) + #考虑最近30天的房价和dglg price_30= consider_time_ss1(junjia,dglg,ppd3,day_30) + #考虑最近60天的房价和dglg price_60= consider_time_ss1(junjia,dglg,ppd3,day_60) if price_15[0]>0: @@ -1290,17 +1316,18 @@ def commonprice(ct, rl, p,weekend): dggg=map_time_price(junjia,dglg,ppd3) - + #当第三方均价的样本量比较大,就可以得出一个非常准确的均价,故直接输出这个价格不考虑房源 + #这一步计算出的价格可信度最高为0.88 if len(junjia)>4 and dglg!=None: sample_size = len(junjia) return dglg, float('%.2f' % credit['0.88']), value_type['第三方'], sample_size - + #这一步在第三方均价算出一个价格之后,并参考房源,计算均价,可信度0.85 elif dggg[0]>0 : return dggg - + #这个一步采用链家和诸葛找房房源聚类出一个价格 elif length > 3: # #####print('ldf=',l_and_z_and_i) pppk = ppd3.loc[l_and_z, :] @@ -1317,6 +1344,10 @@ def commonprice(ct, rl, p,weekend): return int(gm), float('%.2f' % credit['0.8']), value_type['自身样本'], sample_size # 优质样本 + + + + elif data.shape[0] > 0: data['avg'] = data['total_price'] / data['area'] @@ -1645,17 +1676,21 @@ def pt_up(ct, rl, p, weekend, c_date, cmd_estate_type): }, True ) - +#本函数用于将计算出的价格保存到数据库 @timer def out_put_price(ct, rl, lk, weekend): + #提取本小区的信息 lf = region_district_list_lk(ct, rl, lk) if lf.shape[0]>0: + lf = add_alias(lf) + #p是一个列表['小区名','小区别名','物业类型'] p = ghhh(lf[['name', 'alias', 'estate_type2']])[0] ######print('p=', p) #t1=time.time() + #下面函数用于计算价格 mm = commonprice(ct, rl, p,weekend) ##print('mmjisuantime=',time.time()-t1,'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy') ######print('mm=',mm) @@ -1685,7 +1720,8 @@ def out_put_price(ct, rl, lk, weekend): #print('last_sunday_price=',last_sunday_price) # #####print('mm[0]',mm[0]) - + + #计算小区的涨跌幅度 def make_up(avg,last_sunday_price): if type(last_sunday_price) != str and last_sunday_price != None and mm[0] != None and type(mm[0]) != str: @@ -1698,7 +1734,7 @@ def out_put_price(ct, rl, lk, weekend): ######print('make_up',make_up,'*'*20) ######print('credic',mm[1]) - + #对数据进行处理,控制其涨跌幅度 def avg_compare(ct,rl,lk,mm,weekend): avg=fix.price_fix.update(ct,rl,lk,int(mm[0]),weekend) ##print('nihe=',avg) @@ -1714,7 +1750,7 @@ def out_put_price(ct, rl, lk, weekend): #avg=int(mm[0]) - + #计算小区的涨跌幅度 make_up = int(make_up(avg,last_sunday_price)) ##print('s1_time=',time.time()-s1) #avg=mm[0]