5

谁能帮我理解如何将单调约束应用于具有大量特征和行的数据框?如果下面的过程看起来不错,你能告诉我吗?

我有一个包含 750K 行和 88 个特征的数据框。使用 pearson 相关方法为所有特征分配符号,如下所示。

linear_dep = pd.DataFrame()
for col in df.columns:
    linear_dep.loc[col, 'pearson_corr'] = df[col].corr(df.bad)

linear_dep['mono']  = np.where(linear_dep.pearson_corr>0,1,
                              np.where(linear_dep.pearson_corr<0,-1,0))

cols_sort = list(linear_dep.variable)

df_new = df.reindex(columns=cols_sort)

lgb_mono = list(linear_dep['mono'].values)

monotone_constraints=[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

lgb_sk_model = lgb.LGBMClassifier(boosting_type='gbdt', learning_rate=0.01, metric = 'auc',max_depth = 3,subsample = 0.8, colsample_bytree = 0.9, n_estimators=1500)

lgb_sk_model.fit(df_new, df['overall_bad_new'], sample_weight=train_wt,verbose=False)
4

0 回答 0