楼盘评级改为1-5

This commit is contained in:
shenjian@fangjia.com
2023-01-12 17:31:38 +08:00
parent f61af79b35
commit c500e497d7
@@ -16,12 +16,13 @@ log = logging.getLogger(__name__)
es206_client = ElasticSearchClient(host='192.168.0.206')
index_name = "community_summary"
def gmm_train(total_rate, consumption_df, source, target):
# 高斯混合模型
gmm = GaussianMixture(n_components=total_rate).fit(consumption_df[[source]])
consumption_df['cluster'] = gmm.predict(consumption_df[[source]])
consumption_df['price_mean_cluster'] = consumption_df.groupby('cluster')[source].transform('mean')
consumption_df[target] = consumption_df['price_mean_cluster'].rank(method='dense').astype(int)
gmm = GaussianMixture(n_components=total_rate, covariance_type='tied', max_iter=200, n_init=10).fit(consumption_df[[source]])
consumption_df.loc[:, 'cluster'] = gmm.predict(consumption_df[[source]])
consumption_df.loc[:, 'price_mean_cluster'] = consumption_df.groupby('cluster')[source].transform('mean')
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)
return consumption_df
@@ -46,12 +47,12 @@ def calc_price_rating(city=None):
for city in cities:
df = consumption_aim_df[consumption_aim_df['city'] == city].copy()
if len(df) < 10:
if len(df) < 5:
continue
df = gmm_train(10, df, source, target)
if len(df) >= 100:
df = gmm_train(100, df, source, score_target)
df['price_score'] /= 10
df = gmm_train(5, df, source, target)
if len(df) >= 5:
df = gmm_train(5, df, source, score_target)
df['price_score'] /= 5
# 批量更新
for index, item in df.iterrows():