主頁 >  其他 > 最終初學者指南,以資料科學用例贏得分類黑客馬拉松

最終初學者指南,以資料科學用例贏得分類黑客馬拉松

2020-11-11 00:55:16 其他

作者|VETRIVEL_PS
編譯|Flin
來源|analyticsvidhya

總覽

  • 本文是我的第一篇Analytics Vidhya的博客文章的第二部分,該文章是進入機器學習黑客馬拉松的前10%的終極入門者指南,

  • 如果你遵循本文列出的這些簡單步驟,那么贏得黑客馬拉松的分類問題就比較簡單

  • 始終保持不斷的學習,以高度的一致性進行實驗,并遵循你的直覺和你隨著時間積累的領域知識

  • 從幾個月前在Hackathons作為初學者開始,我最近成為了Kaggle專家,并且是 Vidhya 的JanataHack Hackathon系列分析的前5名貢獻者之一,

  • 我在這里分享我的知識,并指導初學者使用Binary分類中的分類用例進行頂級黑客競賽

讓我們深入研究二元分類–來自Analytics Vidhya的JanataHack Hackathon系列的保險交叉銷售用例,并親自進行實驗

鏈接到交叉銷售黑客馬拉松!- https://datahack.analyticsvidhya.com/contest/janatahack-cross-sell-prediction/#ProblemStatement

我們的客戶是一家為客戶提供健康保險的保險公司,現在他們需要我們的幫助來構建模型,以預測過去一年的保單持有人(客戶)是否也會對公司提供的車輛保險感興趣,

保險單是公司承諾為特定的損失,損害,疾病或死亡提供賠償保證,以換取指定的保險費的一種安排,保費是客戶需要定期向保險公司支付此保證金的金額,

例如,我們每年可以為200000盧比的健康保險支付5000盧比的保險費,這樣,如果我們在那一年生病并需要住院治療,保險公司將承擔最高200000盧比的住院費用,現在,如果我們想知道,當公司只收取5000盧比的保險費時,該如何承擔如此高的住院費用,那么,概率的概念就出現了,

例如,像我們一樣,每年可能有100名客戶支付5000盧比的保險費,但只有少數人(比如2-3人)會在當年住院,這樣,每個人都會分擔其他人的風險,

就像醫療保險一樣,有些車輛保險每年需要客戶向保險提供商公司支付一定金額的保險費,這樣,如果車輛不幸發生意外,保險提供商公司將提供賠償(稱為“投保”),

建立模型來預測客戶是否會對車輛保險感興趣對公司非常有幫助,因為它隨后可以相應地計劃其溝通策略,以覆寫這些客戶并優化其業務模型和收入,

分享我的資料科學黑客馬拉松方法——如何在20,000多個資料愛好者中達到前10%

在第1部分中,我們學習可以重復,優化和改進的10個步驟,這是幫助你快速入門的良好基礎,

現在你已經開始練習,讓我們嘗試保險用例來測驗我們的技能,放心,你將在幾個星期的練習中很好地應對任何分類黑客馬拉松(帶有表格資料),希望你熱情,好奇,并通過黑客競賽繼續這一資料科學之旅!

學習,練習和分類黑客馬拉松的10個簡單步驟

1. 理解問題陳述并匯入包和資料集

2. 執行EDA(探索性資料分析)——了解資料集,探索訓練和測驗資料,并了解每個列/特征表示什么,檢查資料集中目標列是否不平衡

3. 從訓練資料檢查重復的行

4. 填充/插補缺失值-連續-平均值/中值/任何特定值|分類-其他/正向填充/回填

5. 特征工程–特征選擇–選擇最重要的現有特征| 特征創建或封裝–從現有特征創建新特征

6. 將訓練資料拆分為特征(獨立變數)| 目標(因變數)

7. 資料編碼–目標編碼,獨熱編碼|資料縮放–MinMaxScaler,StandardScaler,RobustScaler

8. 為二進制分類問題創建基線機器學習模型

9. 結合平均值使用K折交叉驗證改進評估指標“ ROC_AUC”并預測目標“Response”

10. 提交結果,檢查排行榜并改進“ ROC_AUC”

在GitHub鏈接上查看PYTHON中完整的作業代碼以及可用于學習和練習的輸出,只要進行更改,它就會更新!

  • https://github.com/Vetrivel-PS/AV-JanataHack-Insurance-Cross-Sell/blob/main/Latest-AV-Cross-Sell-Post-Hackathon-Analysis-3-ML-Models-in-GPU.ipynb

1. 了解問題陳述并匯入包和資料集

資料集說明

變數 說明
id 客戶的唯一ID
Gender 客戶性別
Age 客戶年齡
Driving_License 0:客戶沒有駕照
1:客戶已經有駕照
Region_Code 客戶所在地區的唯一代碼
Previously_Insured 1:客戶已經有車輛保險
0:客戶沒有車輛保險
Vehicle_Age 車齡
Vehicle_Damage 1:客戶過去曾損壞車輛
0:客戶過去未曾損壞車輛,
Annual_Premium 客戶需要在當年支付的保費金額
Policy_Sales_Channel 與客戶聯系的渠道的匿名代碼,即不同的代理,通過郵件,通過電話,見面等
Vintage 客戶已與公司建立聯系的天數
Response 1:客戶感興趣
0:客戶不感興趣

現在,為了預測客戶是否會對車輛保險感興趣,我們獲得了有關人口統計資訊(性別,年齡,區域代碼型別),車輛(車輛年齡,損壞),保單(保險費,采購渠道)等資訊,

用于檢查所有Hackathon中機器學習模型性能差異的評估指標

在這里,我們將ROC_AUC作為評估指標,

受試者作業特征曲線(ROC)是用于二元分類問題的評價度量,這是一條概率曲線,繪制了各種閾值下的TPR(真陽性率)對FPR(假陽性率),并從本質上將“信號”與“噪聲”分開,所述的曲線下面積(AUC)是一個分類類別之間進行區分的能力的量度,并且被用作ROC曲線的總結,

AUC越高,模型在區分正類和負類方面的性能越好,

  • 當AUC=1時,分類器能夠正確區分所有的正類點和負類點,然而,如果AUC為0,那么分類器將預測所有的陰性為陽性,所有的陽性為陰性,

  • 當0.5 < AUC < 1時,分類器很有可能將正類別值與負類別值區分開,之所以如此,是因為與假陰性和假陽性相比,分類器能夠檢測更多數量的真陽性和真陰性,

  • 當AUC = 0.5時,分類器無法區分正類別點和負類別點,這意味著分類器將為所有資料點預測隨機類別或常量類別,

  • 交叉銷售:訓練資料包含3,81,109個示例,測驗資料包含1,27,037個示例,資料再次出現嚴重失衡——根據訓練資料,僅推薦12.2%(總計3,81,109名員工中的46,709名)晉升,

讓我們從匯入所需的Python包開始

# Import Required Python Packages
# Scientific and Data Manipulation Libraries
import numpy as np
import pandas as pd

# Data Viz & Regular Expression Libraries
import matplotlib.pyplot as plt
import seaborn as sns

# Scikit-Learn Pre-Processing Libraries
from sklearn.preprocessing import *

# Garbage Collection Libraries
import gc

# Boosting Algorithm Libraries
from xgboost import XGBClassifier
from catboost import CatBoostClassifier
from lightgbm import LGBMClassifier

# Model Evaluation Metric & Cross Validation Libraries
from sklearn.metrics import roc_auc_score, auc, roc_curve
from sklearn.model_selection import StratifiedKFold, KFold

# Setting SEED to Reproduce Same Results even with "GPU"
seed_value = https://www.cnblogs.com/panchuangai/archive/2020/11/10/1994
import os
os.environ['PYTHONHASHSEED'} = str(seed_value)
import random
random.seed(seed_value)
import numpy as np
np.random.seed(seed_value)
SEED=seed_value
  1. 科學和資料處理 ——用于使用Numpy處理數字資料,使用Pandas處理表格資料,

  2. 資料可視化庫——Matplotlib和Seaborn用于可視化單個或多個變數,

  3. 資料預處理,機器學習和度量標準庫——用于通過使用評估度量標準(例如ROC_AUC分數)通過編碼,縮放和測量日期來預處理資料,

  4. 提升演算法– XGBoost,CatBoost和LightGBM基于樹的分類器模型用于二進制以及多類分類

  5. 設定SEED –用于將SEED設定為每次重現相同的結果

2. 執行EDA(探索性資料分析)–了解資料集

# Loading data from train, test and submission csv files
train = pd.read_csv('../input/avcrosssellhackathon/train.csv')
test = pd.read_csv('../input/avcrosssellhackathon/test.csv')
sub = pd.read_csv('../input/avcrosssellhackathon/sample_submission.csv')

# Python Method 1 : Displays Data Information
def display_data_information(data, data_types, df)
data.info()
print("\n")
for VARIABLE in data_types :
data_type = data.select_dtypes(include=[ VARIABLE }).dtypes
if len(data_type) > 0 :
print(str(len(data_type))+" "+VARIABLE+" Features\n"+str(data_type)+"\n" )

# Display Data Information of "train" :
data_types = ["float32","float64","int32","int64","object","category","datetime64[ns}"}
display_data_information(train, data_types, "train")

# Display Data Information of "test" :
display_data_information(test, data_types, "test")

# Python Method 2 : Displays Data Head (Top Rows) and Tail (Bottom Rows) of the Dataframe (Table) :
def display_head_tail(data, head_rows, tail_rows)
display("Data Head & Tail :")
display(data.head(head_rows).append(data.tail(tail_rows)))

#     return True
# Displays Data Head (Top Rows) and Tail (Bottom Rows) of the Dataframe (Table)
# Pass Dataframe as "train", No. of Rows in Head = 3 and No. of Rows in Tail = 2 :
display_head_tail(train, head_rows=3, tail_rows=2)

# Python Method 3 : Displays Data Description using Statistics :
def display_data_description(data, numeric_data_types, categorical_data_types)
print("Data Description :")
display(data.describe( include = numeric_data_types))
print("")
display(data.describe( include = categorical_data_types))

# Display Data Description of "train" :
display_data_description(train, data_types[0:4}, data_types[4:7})

# Display Data Description of "test" :
display_data_description(test, data_types[0:4}, data_types[4:7})

讀取CSV格式的資料檔案——pandas的read_csv方法,用于讀取csv檔案,并轉換成類似Data結構的表,稱為DataFrame,因此,為訓練,測驗和提交創建了3個資料幀,

在資料上應用頭尾 –用于查看前3行和后2行以獲取資料概覽,

在資料上應用資訊–用于顯示有關資料幀的列,資料型別和記憶體使用情況的資訊,

在資料上應用描述–用于在數字列上顯示描述統計資訊,例如計數,唯一性,均值,最小值,最大值等,

3. 從訓練資料檢查重復的行

# Removes Data Duplicates while Retaining the First one
def remove_duplicate(data)
data.drop_duplicates(keep="first", inplace=True)
return "Checked Duplicates
# Removes Duplicates from train data
remove_duplicate(train)

檢查訓練資料是否重復——通過保留第一行來洗掉重復的行,在訓練資料中找不到重復項,

4. 填充/插補缺失值-連續-平均值/中值/任何特定值|分類-其他/正向填充/回填

資料中沒有缺失值,

5. 特征工程

# Check train data for Values of each Column - Short Form
for i in train
print(f'column {i} unique values {train[i}.unique()})

# Binary Classification Problem - Target has ONLY 2 Categories
# Target - Response has 2 Values of Customers 1 & 0
# Combine train and test data into single DataFrame - combine_set
combine_set = pd.concat{[train,test},axis=0}
# converting object to int type :
combine_set['Vehicle_Age'}=combine_set['Vehicle_Age'}.replacee({'< 1 Year':0,'1-2 Year':1,'> 2 Years':2})
combine_set['Gender'}=combine_set['Gender'}.replacee({'Male':1,'Female':0})
combine_set['Vehicle_Damage'}=combine_set['Vehicle_Damage'}.replacee({'Yes':1,'No':0})
sns.heatmap(combine_set.corr())

# HOLD - CV - 0.8589 - BEST EVER
combine_set['Vehicle_Damage_per_Vehicle_Age'} = combine_set.groupby(['Region_Code,Age'})['Vehicle_Damage'}.transform('sum'
# Score - 0.858657 (This Feature + Removed Scale_Pos_weight in LGBM) | Rank - 20
combine_set['Customer_Term_in_Years'} = combine_set['Vintage'} / 365
# combine_set['Customer_Term'} = (combine_set['Vintage'} / 365).astype('str')
# Score - 0.85855 | Rank - 20
combine_set['Vehicle_Damage_per_Policy_Sales_Channel'} = combine_set.groupby(['Region_Code,Policy_Sales_Channel'})['Vehicle_Damage'}.transform('sum')
# Score - 0.858527 | Rank - 22
combine_set['Vehicle_Damage_per_Vehicle_Age'} = combine_set.groupby(['Region_Code,Vehicle_Age'})['Vehicle_Damage'}.transform('sum')
# Score - 0.858510 | Rank - 23
combine_set["RANK"} = combine_set.groupby("id")['id'}.rank(method="first", ascending=True)
combine_set["RANK_avg"} = combine_set.groupby("id")['id'}.rank(method="average", ascending=True)
combine_set["RANK_max"} = combine_set.groupby("id")['id'}.rank(method="max", ascending=True)
combine_set["RANK_min"} = combine_set.groupby("id")['id'}.rank(method="min", ascending=True)
combine_set["RANK_DIFF"} = combine_set['RANK_max'} - combine_set['RANK_min'}
# Score - 0.85838 | Rank - 15
combine_set['Vehicle_Damage_per_Vehicle_Age'} = combine_set.groupby([Region_Code})['Vehicle_Damage'}.transform('sum')

# Data is left Skewed as we can see from below distplot
sns.distplot(combine_set['Annual_Premium'})

combine_set['Annual_Premium'} = np.log(combine_set['Annual_Premium'})
sns.distplot(combine_set['Annual_Premium'})

# Getting back Train and Test after Preprocessing :
train=combine_set[combine_set['Response'}.isnull()==False}
test=combine_set[combine_set['Response'}.isnull()==True}.drop(['Response'},axis=1)
train.columns

6. 將訓練資料拆分為特征(獨立變數)| 目標(因變數)

# Split the Train data into predictors and target :
predictor_train = train.drop(['Response','id'],axis=1)
target_train    = train['Response']
predictor_train.head()

# Get the Test data by dropping 'id' :
predictor_test = test.drop(['id'],axis=1)

7. 資料編碼–目標編碼

def add_noise(series, noise_level):
return series * (1 + noise_level * np.random.randn(len(series)))
def target_encode(trn_series=None,
tst_series=None,
target=None,
min_samples_leaf=1,
smoothing=1,
noise_level=0):
"""
Smoothing is computed like in the following paper by Daniele Micci-Barreca
https://kaggle2.blob.core.windows.net/forum-message-attachments/225952/7441/high%20cardinality%20categoricals.pdf

trn_series : training categorical feature as a pd.Series
tst_series : test categorical feature as a pd.Series
target : target data as a pd.Series
min_samples_leaf (int) : minimum samples to take category average into account
smoothing (int) : smoothing effect to balance categorical average vs prior
"""
assert len(trn_series) == len(target)
assert trn_series.name == tst_series.name
temp = pd.concat([trn_series, target], axis=1)
# Compute target mean
averages = temp.groupby(by=trn_series.name)[target.name].agg(["mean", "count"])
# Compute smoothing
smoothing = 1 / (1 + np.exp(-(averages["count"] - min_samples_leaf) / smoothing))
# Apply average function to all target data
prior = target.mean()
# The bigger the count the less full_avg is taken into account
averages[target.name] = prior * (1 - smoothing) + averages["mean"] * smoothing
averages.drop(["mean", "count"], axis=1, inplace=True)
# Apply averages to trn and tst series
ft_trn_series = pd.merge(
trn_series.to_frame(trn_series.name),
averages.reset_index().rename(columns={'index': target.name, target.name: 'average'}),
on=trn_series.name,
how='left')['average'].rename(trn_series.name + '_mean').fillna(prior)
# pd.merge does not keep the index so restore it
ft_trn_series.index = trn_series.index
ft_tst_series = pd.merge(
tst_series.to_frame(tst_series.name),
averages.reset_index().rename(columns={'index': target.name, target.name: 'average'}),
on=tst_series.name,
how='left')['average'].rename(trn_series.name + '_mean').fillna(prior)
# pd.merge does not keep the index so restore it
ft_tst_series.index = tst_series.index
return add_noise(ft_trn_series, noise_level), add_noise(ft_tst_series, noise_level)
# Score - 0.85857 | Rank -
tr_g, te_g = target_encode(predictor_train["Vehicle_Damage"],
predictor_test["Vehicle_Damage"],
target= predictor_train["Response"],
min_samples_leaf=200,
smoothing=20,
noise_level=0.02)
predictor_train['Vehicle_Damage_me']=tr_g
predictor_test['Vehicle_Damage_me']=te_g

8. 為二進制分類問題創建基線機器學習模型

# Baseline Model Without Hyperparameters :
Classifiers = {'0.XGBoost' : XGBClassifier(),
'1.CatBoost' : CatBoostClassifier(),
'2.LightGBM' : LGBMClassifier()
}
# Fine Tuned Model With-Hyperparameters :
Classifiers = {'0.XGBoost' : XGBClassifier(eval_metric='auc',

# GPU PARAMETERS #
tree_method='gpu_hist',
gpu_id=0,

# GPU PARAMETERS #
random_state=294,
learning_rate=0.15,
max_depth=4,
n_estimators=494,
objective='binary:logistic'),
'1.CatBoost' : CatBoostClassifier(eval_metric='AUC',

# GPU PARAMETERS #
task_type='GPU',
devices="0",

# GPU PARAMETERS #
learning_rate=0.15,
n_estimators=494,
max_depth=7,
#                             scale_pos_weight=2),

'2.LightGBM' : LGBMClassifier(metric = 'auc',

# GPU PARAMETERS #
device = "gpu",
gpu_device_id =0,
max_bin = 63,
gpu_platform_id=1,

# GPU PARAMETERS #
n_estimators=50000,
bagging_fraction=0.95,
subsample_freq = 2,
objective ="binary",
min_samples_leaf= 2,
importance_type = "gain",
verbosity = -1,
random_state=294,
num_leaves = 300,
boosting_type = 'gbdt',
learning_rate=0.15,
max_depth=4,

# scale_pos_weight=2, # Score - 0.85865 | Rank - 18
n_jobs=-1)
}

9. 結合平均值使用K折交叉驗證改進評估指標“ ROC_AUC”并預測目標“Response”

# LightGBM Model
kf=KFold(n_splits=10,shuffle=True)
preds_1   = list()
y_pred_1  = []
rocauc_score = []
for i,(train_idx,val_idx) in enumerate(kf.split(predictor_train)):
X_train, y_train = predictor_train.iloc[train_idx,:], target_train.iloc[train_idx]
X_val, y_val = predictor_train.iloc[val_idx, :], target_train.iloc[val_idx]
print('\nFold: {}\n'.format(i+1))
lg= LGBMClassifier(      metric = 'auc',

# GPU PARAMETERS #
device = "gpu",
gpu_device_id =0,
max_bin = 63,
gpu_platform_id=1,

# GPU PARAMETERS #
n_estimators=50000,
bagging_fraction=0.95,
subsample_freq = 2,
objective ="binary",
min_samples_leaf= 2,
importance_type = "gain",
verbosity = -1,
random_state=294,
num_leaves = 300,
boosting_type = 'gbdt',
learning_rate=0.15,
max_depth=4,
# scale_pos_weight=2, # Score - 0.85865 | Rank - 18
n_jobs=-1
)
lg.fit(X_train, y_train
,eval_set=[(X_train, y_train),(X_val, y_val)]
,early_stopping_rounds=100
,verbose=100
)
roc_auc = roc_auc_score(y_val,lg.predict_proba(X_val)[:, 1])
rocauc_score.append(roc_auc)
preds_1.append(lg.predict_proba(predictor_test [predictor_test.columns])[:, 1])
y_pred_final_1          = np.mean(preds_1,axis=0)
sub['Response']=y_pred_final_1
Blend_model_1 = sub.copy()

print('ROC_AUC - CV Score: {}'.format((sum(rocauc_score)/10)),'\n')
print("Score : ",rocauc_score)

# Download and Show Submission File :
display("sample_submmission",sub)
sub_file_name_1 = "S1. LGBM_GPU_TargetEnc_Vehicle_Damage_me_1994SEED_NoScaler.csv"
sub.to_csv(sub_file_name_1,index=False)
sub.head(5)

# Catboost Model
kf=KFold(n_splits=10,shuffle=True)
preds_2   = list()
y_pred_2  = []
rocauc_score = []
for i,(train_idx,val_idx) in enumerate(kf.split(predictor_train)):
X_train, y_train = predictor_train.iloc[train_idx,:], target_train.iloc[train_idx]
X_val, y_val = predictor_train.iloc[val_idx, :], target_train.iloc[val_idx]
print('\nFold: {}\n'.format(i+1))
cb = CatBoostClassifier( eval_metric='AUC',

# GPU PARAMETERS #
task_type='GPU',
devices="0",

# GPU PARAMETERS #
learning_rate=0.15,
n_estimators=494,
max_depth=7,
#                             scale_pos_weight=2
)
cb.fit(X_train, y_train
,eval_set=[(X_val, y_val)]
,early_stopping_rounds=100
,verbose=100
)
roc_auc = roc_auc_score(y_val,cb.predict_proba(X_val)[:, 1])
rocauc_score.append(roc_auc)
preds_2.append(cb.predict_proba(predictor_test [predictor_test.columns])[:, 1])
y_pred_final_2          = np.mean(preds_2,axis=0)
sub['Response']=y_pred_final_2

print('ROC_AUC - CV Score: {}'.format((sum(rocauc_score)/10)),'\n')
print("Score : ",rocauc_score)

# Download and Show Submission File :
display("sample_submmission",sub)
sub_file_name_2 = "S2. CB_GPU_TargetEnc_Vehicle_Damage_me_1994SEED_LGBM_NoScaler_MyStyle.csv"
sub.to_csv(sub_file_name_2,index=False)
Blend_model_2 = sub.copy()
sub.head(5)

# XGBOOST Model
kf=KFold(n_splits=10,shuffle=True)
preds_3   = list()
y_pred_3  = []
rocauc_score = []
for i,(train_idx,val_idx) in enumerate(kf.split(predictor_train)):
X_train, y_train = predictor_train.iloc[train_idx,:], target_train.iloc[train_idx]
X_val, y_val = predictor_train.iloc[val_idx, :], target_train.iloc[val_idx]
print('\nFold: {}\n'.format(i+1))
xg=XGBClassifier( eval_metric='auc',

# GPU PARAMETERS #
tree_method='gpu_hist',
gpu_id=0,

# GPU PARAMETERS #
random_state=294,
learning_rate=0.15,
max_depth=4,
n_estimators=494,
objective='binary:logistic'
)
xg.fit(X_train, y_train
,eval_set=[(X_train, y_train),(X_val, y_val)]
,early_stopping_rounds=100
,verbose=100
)
roc_auc = roc_auc_score(y_val,xg.predict_proba(X_val)[:, 1])
rocauc_score.append(roc_auc)
preds_3.append(xg.predict_proba(predictor_test [predictor_test.columns])[:, 1])
y_pred_final_3         = np.mean(preds_3,axis=0)
sub['Response']=y_pred_final_3

print('ROC_AUC - CV Score: {}'.format((sum(rocauc_score)/10)),'\n')
print("Score : ",rocauc_score)

# Download and Show Submission File :
display("sample_submmission",sub)
sub_file_name_3 = "S3. XGB_GPU_TargetEnc_Vehicle_Damage_me_1994SEED_LGBM_NoScaler.csv"
sub.to_csv(sub_file_name_3,index=False)
Blend_model_3 = sub.copy()
sub.head(5)

10. 提交結果,檢查排行榜并改進“ ROC_AUC”

one = Blend_model_2['id'].copy()
Blend_model_1.drop("id", axis=1, inplace=True)
Blend_model_2.drop("id", axis=1, inplace=True)
Blend_model_3.drop("id", axis=1, inplace=True)
Blend = (Blend_model_1 + Blend_model_2 + Blend_model_3)/3
id_df = pd.DataFrame(one, columns=['id'])
id_df.info()
Blend = pd.concat([ id_df,Blend], axis=1)
Blend.info()
Blend.to_csv('S4. Blend of 3 Models - LGBM_CB_XGB.csv',index=False)
display("S4. Blend of 3 Models : ",Blend.head())

k折交叉驗證

交叉驗證是一種重采樣程序,用于在有限的資料樣本上評估機器學習模型,該程序有一個名為k的引數,它表示給定資料樣本要分成的組數,因此,這個程序通常被稱為k折交叉驗證,

提前停止

  • 在機器學習中,提前停止是一種正則化形式,用于在使用迭代方法(例如梯度下降)訓練學習者時避免過擬合,

  • 提前停止規則提供了關于學習者開始過擬合之前可以運行多少次迭代的指導,

  • 檔案- https://scikit-learn.org/stable/auto_examples/ensemble/plot_gradient_boosting_early_stopping.html

如何使GPU上的3種機器學習模型運行得更快

  1. LIGHTGBM中的GPU引數
    • https://lightgbm.readthedocs.io/en/latest/GPU-Performance.html

要使用LightGBM GPU模型:必須啟用“ Internet” –運行以下所有代碼:


# 保持Internet處于“打開”狀態,該狀態位于Kaggle內核的右側->“設定”面板中

# Cell 1:

!rm -r /opt/conda/lib/python3.6/site-packages/lightgbm

!git clone –recursive https://github.com/Microsoft/LightGBM

# Cell 2:

!apt-get install -y -qq libboost-all-dev

# Cell 3:

%% bash

cd LightGBM

rm -r build

mkdir build

cd build

cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..

make -j$(nproc)

# Cell 4:

!cd LightGBM/python-package/;python3 setup.py install –precompile

# Cell 5:

!mkdir -p /etc/OpenCL/vendors && echo “libnvidia-opencl.so.1” > /etc/OpenCL/vendors/nvidia.icd

!rm -r LightGBM


  1. device = “gpu”

  2. gpu_device_id =0

  3. max_bin = 63

  4. gpu_platform_id=1

如何在GPU上實作良好的速度

  1. 你想運行一些經過我們驗證且具有良好加速性能的資料集(包括Higgs, epsilon, Bosch等),以確保設定正確,如果你有多個GPU,請確保將gpu_platform_id和gpu_device_id設定為使用所需的GPU,還要確保你的系統處于空閑狀態(尤其是在使用共享計算機時),以進行準確性性能測量,

  2. GPU在大規模和密集資料集上表現最佳,如果資料集太小,則在GPU上進行計算效率不高,因為資料傳輸開銷可能很大,如果你具有分類功能,請使用categorical_column選項并將其直接輸入到LightGBM中,不要將它們轉換為獨熱變數,

  3. 為了更好地利用GPU,建議使用較少數量的bin,建議設定max_bin = 63,因為它通常不會明顯影響大型資料集上的訓練精度,但是GPU訓練比使用默認bin大小255明顯快得多,對于某些資料集,即使使用15個bin也就足夠了(max_bin = 15 ); 使用15個bin將最大化GPU性能,確保檢查運行日志并驗證是否使用了所需數量的bin,

  4. 盡可能嘗試使用單精度訓練(gpu_use_dp = false),因為大多數GPU(尤其是NVIDIA消費類GPU)的雙精度性能都很差,

2. CATBOOST中的GPU引數

  1. task_type=’GPU’

  2. devices=”0″


引數描述
CatBoost (fit)task_type:用于訓練的處理單元型別,可能的值:(1)中央處理器(2)GPU
CatBoostClassifier(fit)
CatBoostRegressor(fit)
設備:用于訓練的GPU設備的ID(索引從零開始),
格式:
(1)一臺設備的(例如3)
(2)<多個設備的:..:(例如,devices ='0:1:3')
(3)<設備ID1>-<設備IDN>用于一系列設備(例如,devices ='0-3')

3. XGBOOST中的GPU引數

  1. tree_method ='gpu_hist'

  2. gpu_id = 0

用法

將tree_method引數指定為以下演算法之一,

演演算法

tree_method描述
gpu_hist等效于XGBoost快速直方圖演算法,它快得多,并使用更少的記憶體,注意:在比Pascal架構更早的GPU上運行可能會非常緩慢,

支持的引數

引數gpu_hist
subsample?
sampling_method?
colsample_bytree?
colsample_bylevel?
max_bin?
gamma?
gpu_id?
predictor?
grow_policy ?
monotone_constraints?
interaction_constraints?
single_precision_histogram?

黑客馬拉松交叉銷售總結

在這個AV交叉銷售黑客競賽中起作用的“10件事”:

  1. 2個最佳功能:Vehicle_Damage的目標編碼和按Region_Code分組的Vehicle_Damage總和——基于特征重要性-在CV(10折交叉驗證)和LB(公共排行榜)方面有了很大提升,

  2. 基于域的特征:舊車輛的頻率編碼——有所提高,LB得分:0.85838 |LB排名:15

  3. Hackathon Solutions的排名功能:帶來了巨大的推動力,LB得分:0.858510 |LB排名:23

  4. 洗掉“id”欄:帶來了巨大的推動力,

  5. 基于域的特性:每輛車輛的車輛損壞、年齡和地區代碼——有一點提升,LB得分:0.858527 |LB排名:22

  6. 消除年度保險費的偏離值:帶來了巨大的推動力, LB得分: 0.85855 |LB排名: 20

  7. 基于領域的特征:每個地區的車輛損壞,代碼和政策,銷售渠道,基于特征重要性,有一點提升,LB得分:0.85856 |LB排名:20

  8. 用超引數和10-Fold CV對所有3個模型進行了調整,得出了一個穩健的策略和最好的結果,早期停止的輪數=50或100,Scale_pos_weight在這里沒有太大作用,

  9. 基于域的特性:客戶期限以年為單位,因為其他特性也以年為單位,保險回應將基于年數,LB得分:0.858657 |LB排名:18

  10. 綜合/混合所有3個最好的單獨模型:LightGBM、CatBoost和XGBoost,得到了最好的分數,

5件“不管用”的事

  1. 未處理的特征:[ 按年齡分組的車輛損壞總和,按以前投保的車輛損壞總和,按地區代碼分組的車輛損壞計數,按地區代碼分組的車輛最大損壞,按地區代碼分組的最小車輛損壞,按老舊車輛的頻率編碼,車輛年齡的頻率編碼,每月EMI=年度保險費/12,按保險單分組的車輛損壞總額,按車輛年齡分組的車輛損壞總額,按駕駛執照分組的車輛損壞總額 ]

  2. 洗掉與回應不相關的駕駛執照列

  3. 所有特征的獨熱編碼/虛擬編碼

  4. 與未標度資料相比,所有3種標度方法都不起作用——StandardScaler給出了其中最好的LB評分,StandardScaler –0.8581 | MinMaxScaler–0.8580 | RobustScaler–0.8444

  5. 洗掉基于訓練和測驗的Region_Code上的重復代碼根本不起作用

第2部分結束!(系列待續)

如果你覺得這篇文章有幫助,請與資料科學初學者分享,幫助他們開始黑客競賽,因為它解釋了許多步驟,如基于領域知識的特征工程、交叉驗證、提前停止、在GPU中運行3個機器學習模型,對多個模型進行平均組合,最后總結出“哪些技術有效,哪些無效–最后一步將幫助我們節省大量時間和精力,這將提高未來我們對黑客競賽的關注度,

非常感謝你的閱讀!

原文鏈接:https://www.analyticsvidhya.com/blog/2020/10/ultimate-beginners-guide-to-win-classification-hackathons-with-a-data-science-use-case/

歡迎關注磐創AI博客站:
http://panchuang.net/

sklearn機器學習中文官方檔案:
http://sklearn123.com/

歡迎關注磐創博客資源匯總站:
http://docs.panchuang.net/

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/209907.html

標籤:其他

上一篇:Unity正交相機智能包圍物體(組)方案

下一篇:Python教程:檔案、例外處理和其他

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more