
190
|
第
5
章
wt <- ifelse(full_train_set$outcome=='default',
1 / mean(full_train_set$outcome == 'default'), 1)
full_model <- glm(outcome ~ payment_inc_ratio + purpose_ + home_ +
emp_len_+ dti + revol_bal + revol_util,
data=full_train_set, weight=wt, family='quasibinomial')
pred <- predict(full_model)
mean(pred > 0)
[1] 0.5767208
多数
scikit-learn
方法可以在
fit
函数中使用关键字参数
sample_weight
来指定权重:
default_wt = 1 / np.mean(full_train_set.outcome == 'default')
wt = [default_wt if outcome == 'default' else 1
for outcome in full_train_set.outcome]
full_model = LogisticRegression(penalty="l2", C=1e42, solver='liblinear')
full_model.fit(X, y, sample_weight=wt)
print('percentage ...