python lazypredict构建大量基本模型简化机器学习
python库lazypredict
今天给大家分享一个神奇的 python 库,lazypredict
https://github.com/shankarpandala/lazypredict
lazypredict 是一个开源的 Python 库,旨在简化机器学习模型的构建和评估过程。使用 lazypredict 无需太多代码即可帮助构建大量基本模型,并有助于了解哪些模型在无需任何参数调整的情况下效果更好。
此外,该库还自动执行预处理措施,包括使用 SimpleImputer 处理缺失值、使用独热编码或基于特征基数的序数编码对分类特征进行编码,以及使用标准缩放器缩放数据。
库的安装
可以直接使用 pip 进行安装。
pip install lazypredict
回归问题
lazypredict 库中的 LazyRegressor 类用于解决回归问题。
这里,我们使用的数据集是房价预测数据集,它包含数字和分类特征。
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
接下来,我们将数据切分为训练集和测试集。
# 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
执行后,结果会显示模型名称、R 方、均方根误差 (RMSE) 以及运行相应模型所需的时间。

分类问题
在分类问题中,使用的是 LazyClassifier 类。
这里,我使用的数据集是中风预测数据集来作为演示。
# 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构建大量基本模型简化机器学习的详细内容,更多关于python lazypredict机器学习的资料请关注脚本之家其它相关文章!
相关文章
Python实现Word文档转换为图片(JPG、PNG、SVG等常见格式)
将Word文档以图片形式导出,既能方便信息的分享,也能保护数据安全,避免被二次编辑,文本将介绍如何使用 Spire.Doc for Python 库在Python程序中实现Word到图片的批量转换,需要的朋友可以参考下2024-06-06
使用fiddler抓包工具Python requests报错:ValueError: check_h
这篇文章主要介绍了使用fiddler抓包工具Python requests报错:ValueError: check_hostname requires server_hostname的解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-12-12
pycharm中导入模块错误时提示Try to run this command from the system ter
这篇文章主要介绍了pycharm中导入模块错误时提示Try to run this command from the system terminal问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-03-03
Python中urlencode()函数构建URL查询字符串的利器学习
这篇文章主要为大家介绍了Python中urlencode()函数构建URL查询字符串的利器学习,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-10-10


最新评论