<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          魚(yú)佬:電信客戶流失預(yù)測(cè)賽方案!

          共 13551字,需瀏覽 28分鐘

           ·

          2022-06-21 02:23

           Datawhale干貨 
          作者:魚(yú)佬,武漢大學(xué)碩士

          2022科大訊飛:電信客戶流失預(yù)測(cè)挑戰(zhàn)賽

          賽事地址(持續(xù)更新):

          https://challenge.xfyun.cn/topic/info?type=telecom-customer&ch=ds22-dw-zs01

          賽題介紹

          隨著市場(chǎng)飽和度的上升,電信運(yùn)營(yíng)商的競(jìng)爭(zhēng)也越來(lái)越激烈,電信運(yùn)營(yíng)商亟待解決減少用戶流失,延長(zhǎng)用戶生命周期的問(wèn)題。對(duì)于客戶流失率而言,每增加5%,利潤(rùn)就可能隨之降低25%-85%。因此,如何減少電信用戶流失的分析與預(yù)測(cè)至關(guān)重要。

          鑒于此,運(yùn)營(yíng)商會(huì)經(jīng)常設(shè)有客戶服務(wù)部門,該部門的職能主要是做好客戶流失分析,贏回高概率流失的客戶,降低客戶流失率。某電信機(jī)構(gòu)的客戶存在大量流失情況,導(dǎo)致該機(jī)構(gòu)的用戶量急速下降。面對(duì)如此頭疼的問(wèn)題,該機(jī)構(gòu)將部分客戶數(shù)據(jù)開(kāi)放,誠(chéng)邀大家?guī)椭麄兘⒘魇ьA(yù)測(cè)模型來(lái)預(yù)測(cè)可能流失的客戶。

          賽題任務(wù)

          給定某電信機(jī)構(gòu)實(shí)際業(yè)務(wù)中的相關(guān)客戶信息,包含69個(gè)與客戶相關(guān)的字段,其中“是否流失”字段表明客戶會(huì)否會(huì)在觀察日期后的兩個(gè)月內(nèi)流失。任務(wù)目標(biāo)是通過(guò)訓(xùn)練集訓(xùn)練模型,來(lái)預(yù)測(cè)客戶是否會(huì)流失,以此為依據(jù)開(kāi)展工作,提高用戶留存。

          賽題數(shù)據(jù)

          賽題數(shù)據(jù)由訓(xùn)練集和測(cè)試集組成,總數(shù)據(jù)量超過(guò)25w,包含69個(gè)特征字段。為了保證比賽的公平性,將會(huì)從中抽取15萬(wàn)條作為訓(xùn)練集,3萬(wàn)條作為測(cè)試集,同時(shí)會(huì)對(duì)部分字段信息進(jìn)行脫敏。

          特征字段

          客戶ID、地理區(qū)域、是否雙頻、是否翻新機(jī)、當(dāng)前手機(jī)價(jià)格、手機(jī)網(wǎng)絡(luò)功能、婚姻狀況、家庭成人人數(shù)、信息庫(kù)匹配、預(yù)計(jì)收入、信用卡指示器、當(dāng)前設(shè)備使用天數(shù)、在職總月數(shù)、家庭中唯一訂閱者的數(shù)量、家庭活躍用戶數(shù)、....... 、過(guò)去六個(gè)月的平均每月使用分鐘數(shù)、過(guò)去六個(gè)月的平均每月通話次數(shù)、過(guò)去六個(gè)月的平均月費(fèi)用、是否流失

          評(píng)分標(biāo)準(zhǔn)

          賽題使用AUC作為評(píng)估指標(biāo),即:

          from sklearn import metrics

          auc = metrics.roc_auc_score(data['default_score_true'], data['default_score_pred'])

          賽題baseline

          導(dǎo)入模塊

          import pandas as pd
          import os
          import gc
          import lightgbm as lgb
          import xgboost as xgb
          from catboost import CatBoostRegressor
          from sklearn.linear_model import SGDRegressor, LinearRegression, Ridge
          from sklearn.preprocessing import MinMaxScaler
          from gensim.models import Word2Vec
          import math
          import numpy as np
          from tqdm import tqdm
          from sklearn.model_selection import StratifiedKFold, KFold
          from sklearn.metrics import accuracy_score, f1_score, roc_auc_score, log_loss
          import matplotlib.pyplot as plt
          import time
          import warnings
          warnings.filterwarnings('ignore')

          數(shù)據(jù)預(yù)處理

          train = pd.read_csv('train.csv')
          test = pd.read_csv('test.csv')
          data = pd.concat([train, test], axis=0, ignore_index=True)

          訓(xùn)練數(shù)據(jù)/測(cè)試數(shù)據(jù)準(zhǔn)備

          features = [f for f in data.columns if f not in ['是否流失','客戶ID']]

          train = data[data['是否流失'].notnull()].reset_index(drop=True)
          test = data[data['是否流失'].isnull()].reset_index(drop=True)

          x_train = train[features]
          x_test = test[features]

          y_train = train['是否流失']

          構(gòu)建模型

          def cv_model(clf, train_x, train_y, test_x, clf_name):
              folds = 5
              seed = 2022
              kf = KFold(n_splits=folds, shuffle=True, random_state=seed)

              train = np.zeros(train_x.shape[0])
              test = np.zeros(test_x.shape[0])

              cv_scores = []

              for i, (train_index, valid_index) in enumerate(kf.split(train_x, train_y)):
                  print('************************************ {} ************************************'.format(str(i+1)))
                  trn_x, trn_y, val_x, val_y = train_x.iloc[train_index], train_y[train_index], train_x.iloc[valid_index], train_y[valid_index]

                  if clf_name == "lgb":
                      train_matrix = clf.Dataset(trn_x, label=trn_y)
                      valid_matrix = clf.Dataset(val_x, label=val_y)

                      params = {
                          'boosting_type''gbdt',
                          'objective''binary',
                          'metric''auc',
                          'min_child_weight'5,
                          'num_leaves'2 ** 5,
                          'lambda_l2'10,
                          'feature_fraction'0.7,
                          'bagging_fraction'0.7,
                          'bagging_freq'10,
                          'learning_rate'0.2,
                          'seed'2022,
                          'n_jobs':-1
                      }

                      model = clf.train(params, train_matrix, 50000, valid_sets=[train_matrix, valid_matrix], 
                                        categorical_feature=[], verbose_eval=3000, early_stopping_rounds=200)
                      val_pred = model.predict(val_x, num_iteration=model.best_iteration)
                      test_pred = model.predict(test_x, num_iteration=model.best_iteration)
                      
                      print(list(sorted(zip(features, model.feature_importance("gain")), key=lambda x: x[1], reverse=True))[:20])
                          
                  if clf_name == "xgb":
                      train_matrix = clf.DMatrix(trn_x , label=trn_y)
                      valid_matrix = clf.DMatrix(val_x , label=val_y)
                      test_matrix = clf.DMatrix(test_x)
                      
                      params = {'booster''gbtree',
                                'objective''binary:logistic',
                                'eval_metric''auc',
                                'gamma'1,
                                'min_child_weight'1.5,
                                'max_depth'5,
                                'lambda'10,
                                'subsample'0.7,
                                'colsample_bytree'0.7,
                                'colsample_bylevel'0.7,
                                'eta'0.2,
                                'tree_method''exact',
                                'seed'2020,
                                'nthread'36,
                                "silent"True,
                                }
                      
                      watchlist = [(train_matrix, 'train'),(valid_matrix, 'eval')]
                      
                      model = clf.train(params, train_matrix, num_boost_round=50000, evals=watchlist, verbose_eval=3000, early_stopping_rounds=200)
                      val_pred  = model.predict(valid_matrix, ntree_limit=model.best_ntree_limit)
                      test_pred = model.predict(test_matrix , ntree_limit=model.best_ntree_limit)
                           
                  if clf_name == "cat":
                      params = {'learning_rate'0.2'depth'5'l2_leaf_reg'10'bootstrap_type''Bernoulli',
                                'od_type''Iter''od_wait'50'random_seed'11'allow_writing_files'False}
                      
                      model = clf(iterations=20000, **params)
                      model.fit(trn_x, trn_y, eval_set=(val_x, val_y),
                                cat_features=[], use_best_model=True, verbose=3000)
                      
                      val_pred  = model.predict(val_x)
                      test_pred = model.predict(test_x)
                      
                  train[valid_index] = val_pred
                  test = test_pred / kf.n_splits
                  cv_scores.append(roc_auc_score(val_y, val_pred))
                  
                  print(cv_scores)
                 
              print("%s_scotrainre_list:" % clf_name, cv_scores)
              print("%s_score_mean:" % clf_name, np.mean(cv_scores))
              print("%s_score_std:" % clf_name, np.std(cv_scores))
              return train, test
              
          def lgb_model(x_train, y_train, x_test):
              lgb_train, lgb_test = cv_model(lgb, x_train, y_train, x_test, "lgb")
              return lgb_train, lgb_test

          def xgb_model(x_train, y_train, x_test):
              xgb_train, xgb_test = cv_model(xgb, x_train, y_train, x_test, "xgb")
              return xgb_train, xgb_test

          def cat_model(x_train, y_train, x_test):
              cat_train, cat_test = cv_model(CatBoostRegressor, x_train, y_train, x_test, "cat"
              return cat_train, cat_test
              
          lgb_train, lgb_test = lgb_model(x_train, y_train, x_test)

          提交結(jié)果

          test['是否流失'] = lgb_test
          test[['客戶ID','是否流失']].to_csv('test_sub.csv', index=False)


          數(shù)據(jù)挖掘賽事交流群

          如果群滿,關(guān)注Datawhale公眾號(hào),回復(fù)“數(shù)據(jù)挖掘”或“CV或“NLP”可邀請(qǐng)加入各自戰(zhàn)隊(duì)群,除了經(jīng)驗(yàn)交流,賽題也會(huì)在群內(nèi)更新發(fā)布。

          一鍵三連,一起學(xué)習(xí)?? 

          瀏覽 47
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  黄色视频福利导航 | 五月欧美激激激综合网色播 | 日本韩国操逼 | 理论在线视频 | 国产一区在线视频 |