python?lazypredict構(gòu)建大量基本模型簡化機(jī)器學(xué)習(xí)
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)文章
Python實現(xiàn)Word文檔轉(zhuǎn)換為圖片(JPG、PNG、SVG等常見格式)
將Word文檔以圖片形式導(dǎo)出,既能方便信息的分享,也能保護(hù)數(shù)據(jù)安全,避免被二次編輯,文本將介紹如何使用 Spire.Doc for Python 庫在Python程序中實現(xiàn)Word到圖片的批量轉(zhuǎn)換,需要的朋友可以參考下2024-06-06使用fiddler抓包工具Python requests報錯:ValueError: check_h
這篇文章主要介紹了使用fiddler抓包工具Python requests報錯:ValueError: check_hostname requires server_hostname的解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12python 尋找list中最大元素對應(yīng)的索引方法
今天小編就為大家分享一篇python 尋找list中最大元素對應(yīng)的索引方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06pycharm中導(dǎo)入模塊錯誤時提示Try to run this command from the system ter
這篇文章主要介紹了pycharm中導(dǎo)入模塊錯誤時提示Try to run this command from the system terminal問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03matplotlib圖例、標(biāo)簽、坐標(biāo)軸刻度的字體設(shè)置方式
這篇文章主要介紹了matplotlib圖例、標(biāo)簽、坐標(biāo)軸刻度的字體設(shè)置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05Python中urlencode()函數(shù)構(gòu)建URL查詢字符串的利器學(xué)習(xí)
這篇文章主要為大家介紹了Python中urlencode()函數(shù)構(gòu)建URL查詢字符串的利器學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10