优化财力评级

This commit is contained in:
沈健
2025-04-14 10:56:06 +08:00
parent 146fe2e680
commit 6b4e6ee71e
+20 -11
View File
@@ -85,6 +85,15 @@ def calc_consumption_potential(city):
#
# community_summary_df['estate_charge_fixed'] = QuantileTransformer(output_distribution="normal").fit_transform(
# community_summary_df[['estate_charge_fix']])
# 异常值处理
max_total_price_fixed = community_summary_df['total_price_fixed'].max()
max_avg_cost_fixed = community_summary_df['avg_cost_fixed'].max()
max_estate_charge_fixed = community_summary_df['estate_charge_fixed'].max()
max_relative_price_ranking = community_summary_df['relative_price_ranking'].max()
community_summary_df['total_price_fixed'] = 1 - np.log(community_summary_df['total_price_fixed'] + 1) / np.log(max_total_price_fixed + 1)
community_summary_df['avg_cost_fixed'] = 1 - np.log(community_summary_df['avg_cost_fixed'] + 1) / np.log(max_avg_cost_fixed + 1)
community_summary_df['estate_charge_fixed'] = 1 - np.log(community_summary_df['estate_charge_fixed'] + 1) / np.log(max_estate_charge_fixed + 1)
community_summary_df['relative_price_ranking'] = 1 - np.log(community_summary_df['relative_price_ranking'] + 1) / np.log(max_relative_price_ranking + 1)
community_summary_df['estate_charge_mean'] = community_summary_df.groupby(by=['city'])['estate_charge_fixed'].transform(
np.mean)
@@ -182,18 +191,18 @@ def calc_consumption_rating(community_summary_df):
df = gmm_train(total_rate, df, "avg_cost_score", "avg_cost_rating")
# 计算四分位数和IQR
Q1 = df['consumption_potential'].quantile(0.15)
Q3 = df['consumption_potential'].quantile(0.85)
IQR = Q3 - Q1
# Q1 = df['consumption_potential'].quantile(0.15)
# Q3 = df['consumption_potential'].quantile(0.85)
# IQR = Q3 - Q1
#
# # 定义上下临界点
# upper_bound = Q3 + 1.5 * IQR
#
# # 将超过上临界点的值替换为临界值
# df['robust_potential'] = df['consumption_potential'].clip(upper=upper_bound)
# 定义上下临界点
upper_bound = Q3 + 1.5 * IQR
# 将超过上临界点的值替换为临界值
df['robust_potential'] = df['consumption_potential'].clip(upper=upper_bound)
df = min_max_scale(df, 'robust_potential', 'consumption_score') # 再映射到 [1, 100]
#df = min_max_scale(df, 'consumption_potential', 'consumption_score')
#df = min_max_scale(df, 'robust_potential', 'consumption_score') # 再映射到 [1, 100]
df = min_max_scale(df, 'consumption_potential', 'consumption_score')
if len(score_df) > 0:
# 补充财力评级
df = pd.merge(score_df[['_id', 'total_price_rating', 'total_price_score_minmax']], df, how='left', on=['_id'])