欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python?lazypredict構(gòu)建大量基本模型簡化機(jī)器學(xué)習(xí)

 更新時間:2024年01月22日 10:57:34   作者:小寒聊python  
這篇文章主要介紹了python?lazypredict構(gòu)建大量基本模型簡化機(jī)器學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

python庫lazypredict

今天給大家分享一個神奇的 python 庫,lazypredict

https://github.com/shankarpandala/lazypredict 

lazypredict 是一個開源的 Python 庫,旨在簡化機(jī)器學(xué)習(xí)模型的構(gòu)建和評估過程。使用 lazypredict 無需太多代碼即可幫助構(gòu)建大量基本模型,并有助于了解哪些模型在無需任何參數(shù)調(diào)整的情況下效果更好。

此外,該庫還自動執(zhí)行預(yù)處理措施,包括使用 SimpleImputer 處理缺失值、使用獨熱編碼或基于特征基數(shù)的序數(shù)編碼對分類特征進(jìn)行編碼,以及使用標(biāo)準(zhǔn)縮放器縮放數(shù)據(jù)。

庫的安裝

可以直接使用 pip 進(jìn)行安裝。

pip install lazypredict

回歸問題

lazypredict 庫中的 LazyRegressor 類用于解決回歸問題。

這里,我們使用的數(shù)據(jù)集是房價預(yù)測數(shù)據(jù)集,它包含數(shù)字和分類特征。

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from lazypredict.Supervised import LazyRegressor
housing_data = pd.read_csv('Housing.csv')
housing_data

接下來,我們將數(shù)據(jù)切分為訓(xùn)練集和測試集。

# dropping the target column from the input feature
x_data = housing_data.drop('price', axis=1)

# assigning the target feature 
y_data = housing_data['price']

# splitting the data to train and test set
X_train, X_test, y_train, y_test = train_test_split(x_data, y_data,test_size=.2,random_state =123)

然后,讓我們使用 LazyRegressor 定義回歸模型。

lzy_regressor = LazyRegressor(verbose=0,ignore_warnings=True, custom_metric=None, predictions=True, regressors ='all' )
regressor_model,predictions = lzy_regressor.fit(X_train, X_test, y_train, y_test)
regressor_model

執(zhí)行后,結(jié)果會顯示模型名稱、R 方、均方根誤差 (RMSE) 以及運行相應(yīng)模型所需的時間。

分類問題

在分類問題中,使用的是 LazyClassifier 類。

這里,我使用的數(shù)據(jù)集是中風(fēng)預(yù)測數(shù)據(jù)集來作為演示。

# load the data
stroke_data = pd.read_csv('healthcare-dataset-stroke-data.csv')
stroke_data= stroke_data.drop('id', axis =1) # remove unnecessary column
stroke_data

from lazypredict.Supervised import LazyClassifier

# defining x_input and y_target 
x_data = stroke_data.drop('stroke', axis=1)
y_data = stroke_data['stroke']

# train-test split
X_train, X_test, y_train, y_test = train_test_split(x_data, y_data,test_size=0.2,random_state =123)

# define the lazyclassifiy model and run
lzy_classifier = LazyClassifier(verbose=0,ignore_warnings=True, custom_metric=None, predictions=True, classifiers='all' )
classifier_model ,predictions = lzy_classifier.fit(X_train, X_test, y_train, y_test)
classifier_model

以上就是python lazypredict構(gòu)建大量基本模型簡化機(jī)器學(xué)習(xí)的詳細(xì)內(nèi)容,更多關(guān)于python lazypredict機(jī)器學(xué)習(xí)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論