From 6b4e6ee71e84babfd04191c0fd3e0bcf79dc5d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Mon, 14 Apr 2025 10:56:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=A2=E5=8A=9B=E8=AF=84?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/community/consumption.py | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/dags/business/business/community/consumption.py b/dags/business/business/community/consumption.py index 31f5816..763103d 100644 --- a/dags/business/business/community/consumption.py +++ b/dags/business/business/community/consumption.py @@ -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'])