国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

數(shù)據(jù)分析 | 調(diào)用Optuna庫實現(xiàn)基于TPE的貝葉斯優(yōu)化 | 以隨機森林回歸為例

這篇具有很好參考價值的文章主要介紹了數(shù)據(jù)分析 | 調(diào)用Optuna庫實現(xiàn)基于TPE的貝葉斯優(yōu)化 | 以隨機森林回歸為例。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1. Optuna庫的優(yōu)勢

? ? ? ? 對比bayes_opt和hyperoptOptuna不僅可以銜接到PyTorch等深度學習框架上,還可以與sklearn-optimize結合使用,這也是我最喜歡的地方,Optuna因此特性可以被使用于各種各樣的優(yōu)化場景。

數(shù)據(jù)分析 | 調(diào)用Optuna庫實現(xiàn)基于TPE的貝葉斯優(yōu)化 | 以隨機森林回歸為例,數(shù)據(jù)分析,數(shù)據(jù)分析,隨機森林,筆記,數(shù)據(jù)挖掘,python?

2. 導入必要的庫及加載數(shù)據(jù)

? ? ? ? 用的是sklearn自帶的房價數(shù)據(jù),只是我把它保存下來了。

import optuna
import pandas as pd
import numpy as np
from sklearn.model_selection import KFold,cross_validate
print(optuna.__version__)
from sklearn.ensemble import RandomForestRegressor as RFR
data = pd.read_csv(r'D:\2暫存文件\Sth with Py\貝葉斯優(yōu)化\data.csv')
X = data.iloc[:,0:8]
y = data.iloc[:,8]

3.?定義目標函數(shù)與參數(shù)空間

? ? ? ? Optuna相對于其他庫,不需要單獨輸入?yún)?shù)或參數(shù)空間,只需要直接在目標函數(shù)中定義參數(shù)空間即可。這里以負均方誤差為損失函數(shù)。

def optuna_objective(trial) :
    # 定義參數(shù)空間
    n_estimators = trial.suggest_int('n_estimators',10,100,1)
    max_depth = trial.suggest_int('max_depth',10,50,1)
    max_features = trial.suggest_int('max_features',10,30,1)
    min_impurtity_decrease = trial.suggest_float('min_impurity_decrease',0.0, 5.0, step=0.1)

    # 定義評估器
    reg = RFR(n_estimators=n_estimators,
              max_depth=max_depth,
              max_features=max_features,
              min_impurity_decrease=min_impurtity_decrease,
              random_state=1412,
              verbose=False,
              n_jobs=-1)

    # 定義交叉過程,輸出負均方誤差
    cv = KFold(n_splits=5,shuffle=True,random_state=1412)
    validation_loss = cross_validate(reg,X,y,
                                     scoring='neg_mean_squared_error',
                                     cv=cv,
                                     verbose=True,
                                     n_jobs=-1,
                                     error_score='raise')
    return np.mean(validation_loss['test_score'])

4.? 定義優(yōu)化目標函數(shù)

? ? ? ? 在Optuna中我們可以調(diào)用sampler模塊進行選用想要的優(yōu)化算法,比如TPE、GP等等。

def optimizer_optuna(n_trials,algo):

    # 定義使用TPE或GP
    if algo == 'TPE':
        algo = optuna.samplers.TPESampler(n_startup_trials=20,n_ei_candidates=30)
    elif algo == 'GP':
        from optuna.integration import SkoptSampler
        import skopt
        algo = SkoptSampler(skopt_kwargs={'base_estimator':'GP',
                                          'n_initial_points':10,
                                          'acq_func':'EI'})
    study = optuna.create_study(sampler=algo,direction='maximize')
    study.optimize(optuna_objective,n_trials=n_trials,show_progress_bar=True)

    print('best_params:',study.best_trial.params,
              'best_score:',study.best_trial.values,
              '\n')

    return study.best_trial.params, study.best_trial.values

5. 執(zhí)行部分

import warnings
warnings.filterwarnings('ignore',message='The objective has been evaluated at this point before trails')
optuna.logging.set_verbosity(optuna.logging.ERROR)
best_params, best_score = optimizer_optuna(200,'TPE')

6. 完整代碼

import optuna
import pandas as pd
import numpy as np
from sklearn.model_selection import KFold,cross_validate
print(optuna.__version__)
from sklearn.ensemble import RandomForestRegressor as RFR

data = pd.read_csv(r'D:\2暫存文件\Sth with Py\貝葉斯優(yōu)化\data.csv')
X = data.iloc[:,0:8]
y = data.iloc[:,8]

def optuna_objective(trial) :
    # 定義參數(shù)空間
    n_estimators = trial.suggest_int('n_estimators',10,100,1)
    max_depth = trial.suggest_int('max_depth',10,50,1)
    max_features = trial.suggest_int('max_features',10,30,1)
    min_impurtity_decrease = trial.suggest_float('min_impurity_decrease',0.0, 5.0, step=0.1)

    # 定義評估器
    reg = RFR(n_estimators=n_estimators,
              max_depth=max_depth,
              max_features=max_features,
              min_impurity_decrease=min_impurtity_decrease,
              random_state=1412,
              verbose=False,
              n_jobs=-1)

    # 定義交叉過程,輸出負均方誤差
    cv = KFold(n_splits=5,shuffle=True,random_state=1412)
    validation_loss = cross_validate(reg,X,y,
                                     scoring='neg_mean_squared_error',
                                     cv=cv,
                                     verbose=True,
                                     n_jobs=-1,
                                     error_score='raise')
    return np.mean(validation_loss['test_score'])

def optimizer_optuna(n_trials,algo):

    # 定義使用TPE或GP
    if algo == 'TPE':
        algo = optuna.samplers.TPESampler(n_startup_trials=20,n_ei_candidates=30)
    elif algo == 'GP':
        from optuna.integration import SkoptSampler
        import skopt
        algo = SkoptSampler(skopt_kwargs={'base_estimator':'GP',
                                          'n_initial_points':10,
                                          'acq_func':'EI'})
    study = optuna.create_study(sampler=algo,direction='maximize')
    study.optimize(optuna_objective,n_trials=n_trials,show_progress_bar=True)

    print('best_params:',study.best_trial.params,
              'best_score:',study.best_trial.values,
              '\n')

    return study.best_trial.params, study.best_trial.values

import warnings
warnings.filterwarnings('ignore',message='The objective has been evaluated at this point before trails')
optuna.logging.set_verbosity(optuna.logging.ERROR)
best_params, best_score = optimizer_optuna(200,'TPE')








數(shù)據(jù)分析 | 調(diào)用Optuna庫實現(xiàn)基于TPE的貝葉斯優(yōu)化 | 以隨機森林回歸為例,數(shù)據(jù)分析,數(shù)據(jù)分析,隨機森林,筆記,數(shù)據(jù)挖掘,python

?文章來源地址http://www.zghlxwxcb.cn/news/detail-652495.html

到了這里,關于數(shù)據(jù)分析 | 調(diào)用Optuna庫實現(xiàn)基于TPE的貝葉斯優(yōu)化 | 以隨機森林回歸為例的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • Meta分析的選題與文獻計量分析CiteSpace應用丨R語言Meta分析【數(shù)據(jù)清洗、精美作圖、回歸分析、診斷分析、不確定性及貝葉斯應用】

    Meta分析的選題與文獻計量分析CiteSpace應用丨R語言Meta分析【數(shù)據(jù)清洗、精美作圖、回歸分析、診斷分析、不確定性及貝葉斯應用】

    目錄 ?專題一、Meta分析的選題與文獻計量分析CiteSpace應用 專題二、Meta分析與R語言數(shù)據(jù)清洗及相關應用 專題三、R語言Meta分析與精美作圖 專題四、R語言Meta回歸分析 專題五、R語言Meta診斷分析與進階 專題六、R語言Meta分析的不確定性及貝葉斯應用 專題七、深度拓展機器學習

    2024年02月15日
    瀏覽(26)
  • python-大數(shù)據(jù)分析-基于大數(shù)據(jù)的QQ音樂數(shù)據(jù)分析系統(tǒng)設計與實現(xiàn)

    python-大數(shù)據(jù)分析-基于大數(shù)據(jù)的QQ音樂數(shù)據(jù)分析系統(tǒng)設計與實現(xiàn)

    DESIGN DESCRIPTION After hundreds of years of development of digital music market at home and abroad, the total number of music works collected has reached a considerable degree. Faced with such a large number of music works, how to let users hear their favorite music works more conveniently and efficiently is a matter that music platforms must consider, and

    2024年02月03日
    瀏覽(24)
  • 基于大數(shù)據(jù)的旅游數(shù)據(jù)分析系統(tǒng)的設計與實現(xiàn)

    基于大數(shù)據(jù)的旅游數(shù)據(jù)分析系統(tǒng)的設計與實現(xiàn)

    基于大數(shù)據(jù)的旅游數(shù)據(jù)分析系統(tǒng)的設計與實現(xiàn) 摘??? 要 網(wǎng)絡技術的不斷發(fā)展,使網(wǎng)絡成為人們的日常生活中不可缺少的一部分,而旅游數(shù)據(jù)分析系統(tǒng)是網(wǎng)絡的一種新型體現(xiàn),它以其特有的便捷和快速的特點得到了廣泛的認可。當前的旅游數(shù)據(jù)分析系統(tǒng)不僅沒有建立起整體的

    2024年02月06日
    瀏覽(27)
  • 基于API的視頻分析:實現(xiàn)視頻數(shù)據(jù)的可視化分析

    作者:禪與計算機程序設計藝術 在當今信息化的社會中,視頻監(jiān)控已經(jīng)成為了人們生活中不可或缺的一部分。同時,視頻分析也成為了有效決策、安全監(jiān)控等方面的重要手段。本文旨在通過基于API的視頻分析,實現(xiàn)視頻數(shù)據(jù)的可視化分析,為相關領域提供技術支持。 引言

    2024年02月13日
    瀏覽(22)
  • 項目分享:基于大數(shù)據(jù)的股票數(shù)據(jù)分析系統(tǒng)設計與實現(xiàn)

    項目分享:基于大數(shù)據(jù)的股票數(shù)據(jù)分析系統(tǒng)設計與實現(xiàn)

    A. 研究背景和意義 隨著互聯(lián)網(wǎng)和金融行業(yè)的發(fā)展,股票市場已成為重要的投資渠道,股票數(shù)據(jù)分析技術也成為了投資決策的重要依據(jù)。基于大數(shù)據(jù)技術的股票數(shù)據(jù)分析系統(tǒng)可以實現(xiàn)對股票市場的全面分析和預測,對投資者的決策提供有力的支持。因此,開發(fā)一套基于大數(shù)據(jù)的

    2024年02月02日
    瀏覽(24)
  • 基于Hadoop的電商數(shù)據(jù)分析系統(tǒng)設計與實現(xiàn)

    基于Hadoop的電商數(shù)據(jù)分析系統(tǒng)設計與實現(xiàn) Design and Implementation of E-commerce Data Analysis System based on Hadoop 目錄 2 摘要 3 3 第一章 緒論 4 1.1 研究背景 4 1.2 研究目的與意義 5 1.3 現(xiàn)有研究綜述 6 第二章 Hadoop技術介紹 8 2.1 Hadoop概述 8 2.2 Hadoop生態(tài)系統(tǒng) 9 2.3 Hadoop數(shù)據(jù)處理模型 10 第

    2024年02月04日
    瀏覽(19)
  • 基于Hadoop的京東商城數(shù)據(jù)分析的研究與實現(xiàn)

    題目 基于 Hadoop 的京東商城數(shù)據(jù)分析的研究與實現(xiàn) 1. 課題研究立項依據(jù) (1)課題來源 隨著互聯(lián)網(wǎng)信息技術的發(fā)展,企業(yè)商務模式也發(fā)生了翻天覆地的變化,很多傳統(tǒng)企業(yè)都把目光投向了互聯(lián)網(wǎng)電子商務。近年來,越來越多的電子商務平臺的誕生,引起了電子商務業(yè)內(nèi)的廣泛

    2024年02月06日
    瀏覽(28)
  • 基于Python+django影片數(shù)據(jù)爬取與數(shù)據(jù)分析設計與實現(xiàn)

    基于Python+django影片數(shù)據(jù)爬取與數(shù)據(jù)分析設計與實現(xiàn)

    博主介紹 : ? 全網(wǎng)粉絲30W+,csdn特邀作者、博客專家、CSDN新星計劃導師、Java領域優(yōu)質(zhì)創(chuàng)作者,博客之星、掘金/華為云/阿里云/InfoQ等平臺優(yōu)質(zhì)作者、專注于Java技術領域和畢業(yè)項目實戰(zhàn) ? ?? 文末獲取源碼聯(lián)系 ?? ?????精彩專欄 推薦訂閱 ?????不然下次找不到喲 2022-2024年

    2024年02月05日
    瀏覽(25)
  • BS1066-基于大數(shù)據(jù)爬蟲實現(xiàn)互聯(lián)網(wǎng)研發(fā)崗位數(shù)據(jù)分析平臺

    BS1066-基于大數(shù)據(jù)爬蟲實現(xiàn)互聯(lián)網(wǎng)研發(fā)崗位數(shù)據(jù)分析平臺

    本基于大數(shù)據(jù)爬蟲實現(xiàn)互聯(lián)網(wǎng)研發(fā)崗位數(shù)據(jù)分析平臺,系統(tǒng)主要采用java,互聯(lián)網(wǎng)爬蟲技術,動態(tài)圖表echarts,springboot,mysql,mybatisplus,崗位推薦算法,實現(xiàn)基于互聯(lián)網(wǎng)招聘崗位實現(xiàn)針對用戶的崗位推薦, 系統(tǒng)提供招聘崗位網(wǎng)站前臺,系統(tǒng)崗位數(shù)據(jù)分析可視化平臺展示等功能

    2024年02月13日
    瀏覽(23)
  • 基于python社交網(wǎng)絡大數(shù)據(jù)分析系統(tǒng)的設計與實現(xiàn)

    基于python社交網(wǎng)絡大數(shù)據(jù)分析系統(tǒng)的設計與實現(xiàn)

    摘 要 社交網(wǎng)絡大數(shù)據(jù)分析系統(tǒng)是一種能自動從網(wǎng)絡上收集信息的工具,可根據(jù)用戶的需求定向采集特定數(shù)據(jù)信息的工具,本項目通過研究爬取微博網(wǎng)來實現(xiàn)社交網(wǎng)絡大數(shù)據(jù)分析系統(tǒng)功能。對于采集微博熱點群體發(fā)現(xiàn)信息數(shù)量較少的工作而言,實現(xiàn)一個網(wǎng)頁下載程序不會很麻

    2024年02月22日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包