偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

使用MultiTrain在數(shù)據(jù)集上訓練多個機器學習分類模型示例

人工智能 機器學習
MultiTrain是一個python庫,它允許您一次訓練多個機器學習模型,以評估它們在數(shù)據(jù)集上的性能。Python

現(xiàn)在,讓我們用MultiTrain庫訓練一個數(shù)據(jù)集,看看它與傳統(tǒng)的測試模型方法相比是如何工作的。

注意:訓練結(jié)果可作為選擇適合您特定情況的最佳模型的參考。為了使模型執(zhí)行得更好,需要進行更多的超參數(shù)調(diào)優(yōu)。

在本教程中,我們將使用手機價格分類數(shù)據(jù)集(https://www.kaggle.com/datasets/iabhishekofficial/mobile-price-classification)處理一個分類問題

安裝庫

pip install MultiTrain

導入所需的Python庫

要處理這個數(shù)據(jù)集,我們需要導入以下庫

import warnings 
import pandas as pd
import seaborn as sns
from MultiTrain import MultiClassifier
from numpy import mean,
arange from matplotlib import pyplot as plt
warning.filterwarnings('ignore')

導入機器學習數(shù)據(jù)集

現(xiàn)在,讓我們也導入我們將使用的數(shù)據(jù)集

df = pd.read_csv(“train_phone.csv”)

檢查數(shù)據(jù)集標簽是否平衡

我們檢查數(shù)據(jù)集中包含的標簽,以確定它是是否平衡,這將幫助我們決定如何訓練數(shù)據(jù)集。

在運行下面的代碼時,您將發(fā)現(xiàn)數(shù)據(jù)集標簽是均勻分布的。

# price_range is the column name for the labels
df["price_range"].value_counts()

模型訓練

我們將跳過探索性數(shù)據(jù)分析,這里的重點是看看我們?nèi)绾问褂?MultiTrain 來實現(xiàn)它的目的。

下一步是將數(shù)據(jù)集劃分為特征和標簽。

features = df.drop('price_range', axis=1)
labels = df['price_range']

在定義了訓練特征和標簽之后,我們現(xiàn)在需要進一步將它們分為訓練集和測試集。模型將使用訓練集進行訓練,并使用測試集對其性能進行評估。

然后必須在MultiTrain庫中定義MultiClassifier對象。我們正在處理的數(shù)據(jù)集包括四個不同的標簽,這使它成為一個多類問題。

通過定義隨機狀態(tài)參數(shù),在數(shù)據(jù)集上訓練的所有機器學習模型將產(chǎn)生一致的結(jié)果。設(shè)置“cores”為“-1”可以確保訓練使用CPU中的所有內(nèi)核來提高性能。

train = MultiClassifier(random_state=42,
imbalanced=False,
target_class='multiclass',
cores=-1)
# It's important to assign this method to a variable because it
# returns the training and test splits to be used in the fit method
returned_split = train.split(X=features,
y=labels,
randomState=42,
sizeOfTest=0.2)
fit = train.fit(X=features,
y=labels,
splitting=True,
split_data=returned_split,
show_train_score=True)

圖片

您也可以使用 KFold 拆分對數(shù)據(jù)集進行訓練。

train = MultiClassifier(random_state=42,
imbalanced=False,
target_class='multiclass',
cores=-1)
# setting kf to True tells the fit method to use the KFold Split for # training.
fit = train.fit(X=features,
y=labels,
kf=True,
fold=5,
show_train_score=True)

圖片

您還可以將單個模型與scikit-learn實現(xiàn)進行比較,以查看它們是否產(chǎn)生類似的結(jié)果。


責任編輯:華軒 來源: 不靠譜的貓
相關(guān)推薦

2023-11-06 10:50:35

機器學習LIME

2020-08-10 15:05:02

機器學習人工智能計算機

2022-03-28 09:00:00

SQL數(shù)據(jù)庫機器學習

2017-03-24 15:58:46

互聯(lián)網(wǎng)

2022-06-05 21:16:08

機器學習Python

2023-01-11 07:28:49

TensorFlow分類模型

2022-09-19 15:37:51

人工智能機器學習大數(shù)據(jù)

2022-08-15 15:16:20

機器學習圖片深度學習

2025-02-24 08:40:00

神經(jīng)網(wǎng)絡(luò)模型矩陣變換

2024-11-04 00:24:56

2024-11-26 09:33:44

2024-12-26 00:46:25

機器學習LoRA訓練

2018-11-07 09:00:00

機器學習模型Amazon Sage

2024-09-09 11:45:15

ONNX部署模型

2022-07-22 08:00:00

深度學習數(shù)據(jù)機器學習

2023-01-09 08:00:00

遷移學習機器學習數(shù)據(jù)集

2022-04-01 14:50:52

算法架構(gòu)OnFire

2023-09-05 10:41:28

人工智能機器學習

2024-07-01 12:55:50

2021-11-02 09:40:50

TensorFlow機器學習人工智能
點贊
收藏

51CTO技術(shù)棧公眾號