作者|VETRIVEL_PS
编译|Flin
起源|analyticsvidhya

总览

  • 本文是我的第一篇Analytics Vidhya的博客文章的第二局部,该文章是进入机器学习黑客马拉松的前10%的终极入门者指南。
  • 如果你遵循本文列出的这些简略步骤,那么博得黑客马拉松的分类问题就比较简单
  • 始终保持一直的学习,以高度的一致性进行试验,并遵循你的直觉和你随着工夫积攒的畛域常识
  • 从几个月前在Hackathons作为初学者开始,我最近成为了Kaggle专家,并且是 Vidhya 的JanataHack Hackathon系列剖析的前5名贡献者之一。
  • 我在这里分享我的常识,并领导初学者应用Binary分类中的分类用例进行顶级黑客比赛

让咱们深入研究二元分类–来自Analytics Vidhya的JanataHack Hackathon系列的保险穿插销售用例,并亲自进行试验

链接到穿插销售黑客马拉松!- https://datahack.analyticsvid...

咱们的客户是一家为客户提供衰弱保险的保险公司。当初他们须要咱们的帮忙来构建模型,以预测过来一年的保单持有人(客户)是否也会对公司提供的车辆保险感兴趣。

保险单是公司承诺为特定的损失,侵害,疾病或死亡提供抵偿保障,以换取指定的保险费的一种安顿。保费是客户须要定期向保险公司领取此保证金的金额。

例如,咱们每年能够为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-P...

1. 理解问题陈说并导入包和数据集

数据集阐明

变量阐明
id客户的惟一ID
Gender客户性别
Age客户年龄
Driving_License0:客户没有驾照
1:客户曾经有驾照
Region_Code客户所在地区的惟一代码
Previously_Insured1:客户曾经有车辆保险
0:客户没有车辆保险
Vehicle_Age车龄
Vehicle_Damage1:客户过来曾损坏车辆
0:客户过来未曾损坏车辆。
Annual_Premium客户须要在当年领取的保费金额
Policy_Sales_Channel与客户分割的渠道的匿名代码,即不同的代理,通过邮件,通过电话,见面等
Vintage客户已与公司建立联系的天数
Response1:客户感兴趣
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 Librariesimport numpy as npimport pandas as pd# Data Viz & Regular Expression Librariesimport matplotlib.pyplot as pltimport seaborn as sns# Scikit-Learn Pre-Processing Librariesfrom sklearn.preprocessing import *# Garbage Collection Librariesimport gc# Boosting Algorithm Librariesfrom xgboost import XGBClassifierfrom catboost import CatBoostClassifierfrom lightgbm import LGBMClassifier# Model Evaluation Metric & Cross Validation Librariesfrom sklearn.metrics import roc_auc_score, auc, roc_curvefrom sklearn.model_selection import StratifiedKFold, KFold# Setting SEED to Reproduce Same Results even with "GPU"seed_value = 1994import osos.environ['PYTHONHASHSEED'} = str(seed_value)import randomrandom.seed(seed_value)import numpy as npnp.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 filestrain = 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 Informationdef display_data_information(data, data_types, df)data.info()print("\n")for VARIABLE in data_types :data_type = data.select_dtypes(include=[ VARIABLE }).dtypesif 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 onedef remove_duplicate(data)data.drop_duplicates(keep="first", inplace=True)return "Checked Duplicates# Removes Duplicates from train dataremove_duplicate(train)

查看训练数据是否反复——通过保留第一行来删除反复的行。在训练数据中找不到反复项。

4. 填充/插补缺失值-间断-平均值/中值/任何特定值|分类-其余/正向填充/回填

数据中没有缺失值。

5. 特色工程

# Check train data for Values of each Column - Short Formfor i in trainprint(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_setcombine_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 EVERcombine_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 - 20combine_set['Customer_Term_in_Years'} = combine_set['Vintage'} / 365# combine_set['Customer_Term'} = (combine_set['Vintage'} / 365).astype('str')# Score - 0.85855 | Rank - 20combine_set['Vehicle_Damage_per_Policy_Sales_Channel'} = combine_set.groupby(['Region_Code,Policy_Sales_Channel'})['Vehicle_Damage'}.transform('sum')# Score - 0.858527 | Rank - 22combine_set['Vehicle_Damage_per_Vehicle_Age'} = combine_set.groupby(['Region_Code,Vehicle_Age'})['Vehicle_Damage'}.transform('sum')# Score - 0.858510 | Rank - 23combine_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 - 15combine_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 distplotsns.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-Barrecahttps://kaggle2.blob.core.windows.net/forum-message-attachments/225952/7441/high%20cardinality%20categoricals.pdftrn_series : training categorical feature as a pd.Seriestst_series : test categorical feature as a pd.Seriestarget : target data as a pd.Seriesmin_samples_leaf (int) : minimum samples to take category average into accountsmoothing (int) : smoothing effect to balance categorical average vs prior"""assert len(trn_series) == len(target)assert trn_series.name == tst_series.nametemp = pd.concat([trn_series, target], axis=1)# Compute target meanaverages = temp.groupby(by=trn_series.name)[target.name].agg(["mean", "count"])# Compute smoothingsmoothing = 1 / (1 + np.exp(-(averages["count"] - min_samples_leaf) / smoothing))# Apply average function to all target dataprior = target.mean()# The bigger the count the less full_avg is taken into accountaverages[target.name] = prior * (1 - smoothing) + averages["mean"] * smoothingaverages.drop(["mean", "count"], axis=1, inplace=True)# Apply averages to trn and tst seriesft_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 itft_trn_series.index = trn_series.indexft_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 itft_tst_series.index = tst_series.indexreturn 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_gpredictor_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 - 18n_jobs=-1)}

9. 联合平均值应用K折穿插验证改良评估指标“ ROC_AUC”并预测指标“Response”

# LightGBM Modelkf=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 - 18n_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_1Blend_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 Modelkf=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 Modelkf=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)/3id_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/stab...

如何使GPU上的3种机器学习模型运行得更快

  1. LIGHTGBM中的GPU参数

    • https://lightgbm.readthedocs....

要应用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:%% bashcd LightGBMrm -r buildmkdir buildcd buildcmake -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)一台设施的<unit ID>(例如3)
(2)<多个设施的<unit ID1>:<unit ID2>:..:<unit IDN>(例如,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.c...

欢送关注磐创AI博客站:
http://panchuang.net/

sklearn机器学习中文官网文档:
http://sklearn123.com/

欢送关注磐创博客资源汇总站:
http://docs.panchuang.net/