楼盘评级改为1-5
This commit is contained in:
@@ -16,12 +16,13 @@ log = logging.getLogger(__name__)
|
|||||||
es206_client = ElasticSearchClient(host='192.168.0.206')
|
es206_client = ElasticSearchClient(host='192.168.0.206')
|
||||||
index_name = "community_summary"
|
index_name = "community_summary"
|
||||||
|
|
||||||
|
|
||||||
def gmm_train(total_rate, consumption_df, source, target):
|
def gmm_train(total_rate, consumption_df, source, target):
|
||||||
# 高斯混合模型
|
# 高斯混合模型
|
||||||
gmm = GaussianMixture(n_components=total_rate).fit(consumption_df[[source]])
|
gmm = GaussianMixture(n_components=total_rate, covariance_type='tied', max_iter=200, n_init=10).fit(consumption_df[[source]])
|
||||||
consumption_df['cluster'] = gmm.predict(consumption_df[[source]])
|
consumption_df.loc[:, 'cluster'] = gmm.predict(consumption_df[[source]])
|
||||||
consumption_df['price_mean_cluster'] = consumption_df.groupby('cluster')[source].transform('mean')
|
consumption_df.loc[:, 'price_mean_cluster'] = consumption_df.groupby('cluster')[source].transform('mean')
|
||||||
consumption_df[target] = consumption_df['price_mean_cluster'].rank(method='dense').astype(int)
|
consumption_df.loc[:, target] = consumption_df['price_mean_cluster'].rank(method='dense', ascending=False).astype(int)
|
||||||
consumption_df = consumption_df.drop(columns=['cluster', 'price_mean_cluster'], axis=1)
|
consumption_df = consumption_df.drop(columns=['cluster', 'price_mean_cluster'], axis=1)
|
||||||
return consumption_df
|
return consumption_df
|
||||||
|
|
||||||
@@ -46,12 +47,12 @@ def calc_price_rating(city=None):
|
|||||||
|
|
||||||
for city in cities:
|
for city in cities:
|
||||||
df = consumption_aim_df[consumption_aim_df['city'] == city].copy()
|
df = consumption_aim_df[consumption_aim_df['city'] == city].copy()
|
||||||
if len(df) < 10:
|
if len(df) < 5:
|
||||||
continue
|
continue
|
||||||
df = gmm_train(10, df, source, target)
|
df = gmm_train(5, df, source, target)
|
||||||
if len(df) >= 100:
|
if len(df) >= 5:
|
||||||
df = gmm_train(100, df, source, score_target)
|
df = gmm_train(5, df, source, score_target)
|
||||||
df['price_score'] /= 10
|
df['price_score'] /= 5
|
||||||
|
|
||||||
# 批量更新
|
# 批量更新
|
||||||
for index, item in df.iterrows():
|
for index, item in df.iterrows():
|
||||||
|
|||||||
Reference in New Issue
Block a user