优化评级
This commit is contained in:
@@ -19,9 +19,9 @@ 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.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').astype(int)
|
||||
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)
|
||||
consumption_df = consumption_df.drop(columns=['cluster', 'price_mean_cluster'], axis=1)
|
||||
return consumption_df
|
||||
|
||||
@@ -45,7 +45,7 @@ def calc_price_rating(city=None):
|
||||
count = 0
|
||||
|
||||
for city in cities:
|
||||
df = consumption_aim_df[consumption_aim_df['city'] == city]
|
||||
df = consumption_aim_df[consumption_aim_df['city'] == city].copy()
|
||||
if len(df) < 10:
|
||||
continue
|
||||
df = gmm_train(10, df, source, target)
|
||||
@@ -58,7 +58,8 @@ def calc_price_rating(city=None):
|
||||
row = dict()
|
||||
_id = str(item["_id"])
|
||||
row['price_rating'] = item['price_rating']
|
||||
row['price_score'] = item['price_score']
|
||||
if 'price_score' in item:
|
||||
row['price_score'] = item['price_score']
|
||||
|
||||
action = {'_op_type': 'update',
|
||||
'_index': index_name,
|
||||
|
||||
Reference in New Issue
Block a user