R과 python sklearn 모두에서 로지스틱 회귀 모델을 교육하는 데 동일한 데이터 세트를 사용합니다. 데이터 세트의 균형이 맞지 않습니다. 그리고 나는 auc가 아주 다르다는 것을 알았다. 는 R이 0.887 인 반면 파이썬왜 auc가 Sklearn의 로지스틱 회귀와 다른가? R
glm_fit <- glm(label ~ watch_cnt_7 + bid_cnt_7 + vi_cnt_itm_1 +
ITEM_PRICE + add_to_cart_cnt_7 + offer_cnt_7 +
dwell_dlta_4to2 +
vi_cnt_itm_2 + asq_cnt_7 + watch_cnt_14to7 + dwell_dlta_6to4 +
auct_type + vi_cnt_itm_3 + vi_cnt_itm_7 + vi_dlta_4to2 +
vi_cnt_itm_4 + vi_dlta_6to4 + tenure + sum_SRCH_item_7 +
vi_cnt_itm_6 + dwell_itm_3 +
offer_cnt_14to7 + #
dwell_itm_2 + dwell_itm_6 + CNDTN_ROLLUP_ID +
dwell_itm_5 + dwell_itm_4 + dwell_itm_1+
bid_cnt_14to7 + item_prchsd_cnt_14to7 + #
dwell_itm_7 + median_day_rate + vb_ratio
, data = train, family=binomial())
p_lm<-predict(glm_fit, test[1:nc-1],type = "response")
pred_lm <- prediction(p_lm,test$label)
auc <- performance(pred_lm,'auc')@y.values
AUC에가 0.623이다
model_logistic = linear_model.LogisticRegression() #auc 0.623
model_logistic.fit(train_x, train_y)
pred_logistic = model_logistic.predict(test_x) #mean:0.0235 var:0.023
print "logistic auc: ", sklearn.metrics.roc_auc_score(test_y,pred_logistic)
이 R의 코드이다 이 파이썬 코드이다. Sklearn Logistic Regression의 문제점과 해결 방법을 알고 싶습니다. 감사.
'1 : nc-1'이 잘못되었습니다. – rawr
그 오류는별로 중요하지 않습니다. 1 : nc-1은 0 : (nc-1)과 같을 것이고, 이는 선택으로 사용되며 1 : (nc-1)과 동일합니다. – nograpes
작은 재현 가능한 예제를 만든다면 도움이 될 것입니다. 예를 들어 R로 작은 간단한 데이터 세트를 만들면 파이썬과 R에서 모두 읽고 실행할 수 있습니다. 또한, 로지스틱 회귀 계수가 두 모델 모두에서 동일하다는 것을 확인하는 것이 도움이 될 것입니다. – nograpes