<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>

          【機(jī)器學(xué)習(xí)】PyCaret!又一個(gè)神仙的自動(dòng)機(jī)器學(xué)習(xí)庫!

          共 1856字,需瀏覽 4分鐘

           ·

          2021-08-15 11:59

          作者:時(shí)晴


          PyCaret這個(gè)開源工具,用起來可謂簡(jiǎn)單至極,少量代碼就可以搭建各種端到端的模型,廢話不多說,直接看實(shí)戰(zhàn)。


          PyCaret安裝:

          # install slim version (default)pip install pycaret# install the full versionpip install pycaret[full]

          先用PyCaret自帶的'insurance'數(shù)據(jù)集作為例子,我們看下數(shù)據(jù):

          # read data from pycaret repofrom pycaret.datasets import get_datadata = get_data('insurance')


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


          該步驟是使用PyCaret構(gòu)建任何模型強(qiáng)制要做的一步:

          # initialize setupfrom pycaret.regression import *s = setup(data, target = 'charges')

          執(zhí)行完上述代碼后,不僅自動(dòng)推斷了各個(gè)特征的類型,還問你是否推斷正確。

          直接continue,會(huì)彈出setup的分析結(jié)果,如下圖所示:

          從上圖紅框中,我們驚喜的發(fā)現(xiàn)連訓(xùn)練集測(cè)試集都幫忙我們拆分好了,并行已經(jīng)幫我們把訓(xùn)練數(shù)據(jù)shuffle好了。當(dāng)然我們可以自定義拆分比例,如下所示:

          setup(data = insurance, target = 'charges', train_size = 0.5)

          也可以對(duì)數(shù)據(jù)進(jìn)行scale:

          setup(data = pokemon, target = 'Legendary', normalize = True)

          會(huì)默認(rèn)幫你把連續(xù)值,離散值的缺失值處理掉:

          可以對(duì)數(shù)據(jù)進(jìn)行分桶,只需要加上參數(shù)bin_numeric_features

          setup(data = income, target = 'income >50K', bin_numeric_features = ['age'])

          需要進(jìn)行特征篩選的話,也只需要加一個(gè)參數(shù)feature_selection = True:

          setup(data = diabetes, target = 'Class variable', feature_selection = True)

          同樣,一個(gè)參數(shù)連異常值都幫你移除了remove_outliers = True:

          setup(data = insurance, target = 'charges', remove_outliers = True)

          還有各種各樣的預(yù)處理操作,大家可以參考官方文檔。

          https://pycaret.org/preprocessing/


          模型訓(xùn)練


          直接看下我們可以用哪些模型:

          # check all the available modelsmodels()

          真的是應(yīng)有盡有,大部分煉丹師其實(shí)只看到了最下面3個(gè),xgb,lgb,cbt。


          模型訓(xùn)練


          那么我們就用xgb跑下吧:

          # train decision treedt = create_model('xgboost')

          然后啥都不用寫,測(cè)試集上各個(gè)mertic就顯示出來了:

          模型融合是大家最常用的,也只需要一行代碼:

          # train multiple modelsmultiple_models = [create_model(i) for i in ['dt', 'lr', 'xgboost']]

          要比較各個(gè)模型,也只需要一行代碼:

          # compare all modelsbest_model = compare_models()

          模型預(yù)估:

          predictions = predict_model(best_model, data = data2)


          所以,大家數(shù)數(shù)看,我們一共才寫了幾行代碼,就把模型預(yù)處理、訓(xùn)練、驗(yàn)證、融合、預(yù)估全完成了?做表格類數(shù)據(jù)模型真的是太方便了。

          往期精彩回顧




          本站qq群851320808,加入微信群請(qǐng)掃碼:
          瀏覽 93
          點(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>
                  婬荡的寡妇一区二区三区 | 天天操天天干天天爱 | 日本福利视频一区 | 日韩三级中文字幕电影在线 | 国产黄片精品 |