第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用正則化 (L1 / L2) Lasso 和 Ridge 的 Logistic 回歸模型

使用正則化 (L1 / L2) Lasso 和 Ridge 的 Logistic 回歸模型

森林海 2023-12-29 15:57:02
我正在嘗試構(gòu)建模型并創(chuàng)建網(wǎng)格搜索,下面是代碼。原始數(shù)據(jù)是從該網(wǎng)站下載的(信用卡欺詐數(shù)據(jù))。 https://www.kaggle.com/mlg-ulb/creditcardfraud讀取數(shù)據(jù)后從標(biāo)準(zhǔn)化開始編碼。standardization = StandardScaler()credit_card_fraud_df[['Amount']] = standardization.fit_transform(credit_card_fraud_df[['Amount']])# Assigning feature variable to XX = credit_card_fraud_df.drop(['Class'], axis=1)# Assigning response variable to yy = credit_card_fraud_df['Class']# Splitting the data into train and testX_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.7, test_size=0.3, random_state=100)X_train.head()power_transformer = PowerTransformer(copy=False)power_transformer.fit(X_train)                       ## Fit the PT on training dataX_train_pt_df = power_transformer.transform(X_train)    ## Then apply on all dataX_test_pt_df = power_transformer.transform(X_test)y_train_pt_df = y_trainy_test_pt_df = y_testtrain_pt_df = pd.DataFrame(data=X_train_pt_df, columns=X_train.columns.tolist())# set up cross validation schemefolds = StratifiedKFold(n_splits = 5, shuffle = True, random_state = 4)# specify range of hyperparametersparams = {"C":np.logspace(-3,3,5,7), "penalty":["l1","l2"]}# l1 lasso l2 ridge結(jié)果示例:  mean_fit_time std_fit_time    mean_score_time std_score_time  param_C param_penalty   params  split0_test_score   split1_test_score   split2_test_score   split3_test_score   split4_test_score   mean_test_score std_test_score  rank_test_score    0   0.044332    0.002040    0.000000    0.000000    0.001   l1  {'C': 0.001, 'penalty': 'l1'}   NaN NaN NaN NaN NaN NaN NaN 6    1   0.477965    0.046651    0.016745    0.003813    0.001   l2  {'C': 0.001, 'penalty': 'l2'}   0.485714    0.428571    0.542857    0.485714    0.457143    0.480000    0.037904    5我的輸入數(shù)據(jù)中沒有任何空值。我不明白為什么我會(huì)得到這些列的 Nan 值。誰(shuí)能幫幫我嗎?
查看完整描述

1 回答

?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊

您在此處定義的默認(rèn)求解器有問題:


model = LogisticRegression(class_weight='balanced')

這是從以下錯(cuò)誤消息得出的:


ValueError: Solver lbfgs supports only 'l2' or 'none' penalties, got l1 penalty.

此外,在定義參數(shù)網(wǎng)格之前研究文檔可能會(huì)很有用:


penalty: {'l1', 'l2', 'elasticnet', 'none'}, default='l2' 用于指定懲罰中使用的范數(shù)?!皀ewton-cg”、“sag”和“l(fā)bfgs”求解器僅支持 l2 懲罰?!癳lasticnet”僅受“saga”求解器支持。如果為“none”(liblinear 求解器不支持),則不應(yīng)用正則化。


一旦您使用支持所需網(wǎng)格的不同解算器糾正它,您就可以開始:


## using Logistic regression for class imbalance

model = LogisticRegression(class_weight='balanced', solver='saga')

grid_search_cv = GridSearchCV(estimator = model, param_grid = params, 

                        scoring= 'roc_auc', 

                        cv = folds, 

                        return_train_score=True, verbose = 1)            

grid_search_cv.fit(X_train_pt_df, y_train_pt_df)

## reviewing the results

cv_results = pd.DataFrame(grid_search_cv.cv_results_)

另請(qǐng)注意,ConvergenceWarning這可能建議您需要增加默認(rèn)值max_iter、tol或切換到另一個(gè)求解器并重新考慮所需的參數(shù)網(wǎng)格。


查看完整回答
反對(duì) 回復(fù) 2023-12-29
  • 1 回答
  • 0 關(guān)注
  • 201 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)