从将蘑菇分类为可食用或不可食用的分类中学习随机森林分类器

2023-11-21 09:50

本文主要是介绍从将蘑菇分类为可食用或不可食用的分类中学习随机森林分类器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

There are about 50,000 species of mushrooms and out of which 1 to 2 % of them are poisonous. Predicting whether a mushroom is edible or not is a classic problem in the domain of Machine Learning. A mushroom is classified based on a number of features

大约有50,000种蘑菇,其中有1-2%是有毒的。 预测蘑菇是否可食用是机器学习领域的经典问题。 蘑菇根据许多特征分类

什么是RandomForest分类器? (What is a RandomForest Classifier?)

Image for post

A RandomForest Classifier operates as an ensemble algorithm. An ensemble algorithm is the one that combines two more algorithms to derive better results. A RandomForest Classifier is a combination of number of Decision tress. If you do not have an idea of what a Decision Tree is, please visit my blog on Decision Trees.

RandomForest分类器用作集成算法。 集成算法是一种将两种以上算法组合在一起以得出更好结果的算法。 RandomForest分类器是决策树数量的组合。 如果您不知道什么是决策树,请访问我关于决策树的博客。

From the number of decision trees derived the best are chosen and it is fitted to the model.

从得出的决策树数量中选择最佳,然后将其拟合到模型中。

让我们编码! (Let’s Code!)

Now we are going to build a RandomForest Classifier machine learning model using python and some libraries. Libraries are set of programs already written to make the calculations simpler. If you do not know the common machine learning terminologies like Model, Training, etc. please do visit my article on Basic Terminologies of Machine Learning using this link. Let’s start to code!

现在,我们将使用python和一些库来构建RandomForest分类器机器学习模型。 库是已经编写的一组程序,可以简化计算。 如果您不了解诸如Model,Training等常见的机器学习术语,请使用此链接访问我有关机器学习的基本术语的文章。 让我们开始编码!

Image for post

Here we have imported the necessary libraries and packages for us to perform the simple linear regression. The libraries and packages imported are:

在这里,我们已经导入了必要的库和包,以执行简单的线性回归。 导入的库和软件包为:

  1. Numpy: This is a package that is used for scientific calculations and array calculations in python.

    Numpy:这是一个用于在python中进行科学计算和数组计算的软件包。
  2. Pandas: This is a powerful package that has some functions for Data Analysis and Manipulation.

    熊猫:这是一个功能强大的软件包,具有一些用于数据分析和处理的功能。
  3. Sklearn: This is a free machine learning library that contains many functions and methods that are necessary to build a machine learning model. From Sklearn we have imported three functions LabelEncoder, model_selection, and ensemble. LabelEncoder is used to convert the categorical variables into numerical variables and the Ensemble function contains the built-in package for RandomForestClassifier.

    Sklearn:这是一个免费的机器学习库,其中包含构建机器学习模型所需的许多功能和方法。 从Sklearn,我们导入了三个函数LabelEncoder,model_selection和ensemble。 LabelEncoder用于将分类变量转换为数值变量,并且Ensemble函数包含RandomForestClassifier的内置包。
Image for post

Here we are importing the dataset named “mushrooms.csv” and displaying their values before LabelEncoding. The link to the dataset is here.

在这里,我们将导入名为“ mushrooms.csv”的数据集,并在LabelEncoding之前显示其值。 数据集的链接在这里 。

Image for post

Here, we have dropped or deleted the rows that have null values in them to have better predictions. LabelEncoding is the process of converting the categorical or alphabetical values into numerical values as a computer can understand only numerics. And we have also done LabelEncoding here.

在这里,我们删除或删除了其中具有空值的行,以进行更好的预测。 LabelEncoding是将分类或字母值转换为数字值的过程,因为计算机只能理解数字。 而且我们还在这里完成了LabelEncoding。

Image for post

Here, we are selecting the target variable(y) whether a mushroom is edible or not and the features to predict the target variable in the variable(x) and we are splitting the dataset into train and test sets.

在这里,我们选择蘑菇是否可食用的目标变量(y),以及在变量(x)中预测目标变量的特征,然后将数据集分为训练集和测试集。

Image for post

Here, we are initializing the RandomForestClassifier model with the number of decision trees to be formed as “40”. And we are fitting our data to our model.

在这里,我们要初始化的RandomForestClassifier模型的决策树数为“ 40”。 我们正在将数据拟合到模型中。

40 Decision trees will be formed and the best out of them for the two classes Edible or Not-Edible will be selected as the final model.

将形成40个决策树,并从两个类别的可食用或不可食用中选出最好的作为最终模型。

Image for post

At last, we are predicting using the trained model and we are printing whether a mushroom is edible or not.

最后,我们将使用经过训练的模型进行预测,并打印蘑菇是否可食用。

Here is the link to the full code for you to have a hands-on experience. Any queries please do contact me through LinkedIn. Happy Learning!!!

这是完整代码的链接,可让您获得动手经验 。 如有任何疑问,请通过LinkedIn与我联系。 学习愉快!!!

翻译自: https://medium.com/@dilmihirdil123/learn-randomforest-classifier-from-classifying-mushrooms-as-edible-or-not-edible-15fc0cc67c91

原文地址:https://blog.csdn.net/weixin_26704853/article/details/108499206
http://www.taodudu.cc/news/show-8330621.html

相关文章:

  • mushroom蘑菇数据集入门
  • JAVA 通过JSON文件获取王者荣耀壁纸
  • 手把手教你从分析到实现,王者荣耀壁纸爬虫!
  • 企业数据接口API
  • 互联网销售如何找到企业名单 销售找企业方法
  • 查询企业信息范例Coding
  • 信封加密与密钥管理实践
  • 教育类的短视频如何做?三种类型分享,总有一个适合你
  • 计算机声音处理说课稿,《数字化声音编辑》说课稿
  • 2023年09月 Scratch(一级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • 【API解析】微软edge浏览器大声朗读功能(read aloud)调用步骤
  • 2023年9月 少儿编程 中国电子学会图形化编程等级考试Scratch编程一级真题解析(选择题)
  • 超多热门视频都在用的声音|只要一部手机就能制作的配音神器
  • 《铃芽之旅》:自我救赎的奇幻旅程
  • 档案室空气质量监测系统方案,检测温湿度、二氧化碳、甲醛、TVOC、粉尘、PM2.5等,利用现代化物联网技术
  • android实训培训班,蓝鸥Android培训西安邮电大学Android实训课结业了
  • Android培训班(34)
  • Android培训班(52)
  • Android培训班(49)
  • Android培训班(19)
  • Android培训班 75 Dalvik虚拟机的GetStaticMethodID函数
  • Android培训班 全世界最便宜,还送6410开发板
  • Android培训班(29)
  • Android培训班(4)
  • Android培训班(85)升级到4.0版本
  • Android培训班(46)
  • 华为畅享9系统便签和计算机不小心删掉了,手机便签删了怎么恢复
  • 云上数字化时代,华为云桌面助力政企办公升级
  • 华为云桌面,助您解锁轻松高效办公模式
  • 华为云CDN,带你畅享更快速的上网体验
  • 这篇关于从将蘑菇分类为可食用或不可食用的分类中学习随机森林分类器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


    原文地址:https://blog.csdn.net/weixin_26704853/article/details/108499206
    本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/401545

    相关文章

    重新对Java的类加载器的学习方式

    《重新对Java的类加载器的学习方式》:本文主要介绍重新对Java的类加载器的学习方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、简介1.2、符号引用和直接引用1、符号引用2、直接引用3、符号转直接的过程2、加载流程3、类加载的分类3.1、显示

    Python开发文字版随机事件游戏的项目实例

    《Python开发文字版随机事件游戏的项目实例》随机事件游戏是一种通过生成不可预测的事件来增强游戏体验的类型,在这篇博文中,我们将使用Python开发一款文字版随机事件游戏,通过这个项目,读者不仅能够... 目录项目概述2.1 游戏概念2.2 游戏特色2.3 目标玩家群体技术选择与环境准备3.1 开发环境3

    解决IDEA报错:编码GBK的不可映射字符问题

    《解决IDEA报错:编码GBK的不可映射字符问题》:本文主要介绍解决IDEA报错:编码GBK的不可映射字符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录IDEA报错:编码GBK的不可映射字符终端软件问题描述原因分析解决方案方法1:将命令改为方法2:右下jav

    Java学习手册之Filter和Listener使用方法

    《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen

    Pandas使用AdaBoost进行分类的实现

    《Pandas使用AdaBoost进行分类的实现》Pandas和AdaBoost分类算法,可以高效地进行数据预处理和分类任务,本文主要介绍了Pandas使用AdaBoost进行分类的实现,具有一定的参... 目录什么是 AdaBoost?使用 AdaBoost 的步骤安装必要的库步骤一:数据准备步骤二:模型

    Python中随机休眠技术原理与应用详解

    《Python中随机休眠技术原理与应用详解》在编程中,让程序暂停执行特定时间是常见需求,当需要引入不确定性时,随机休眠就成为关键技巧,下面我们就来看看Python中随机休眠技术的具体实现与应用吧... 目录引言一、实现原理与基础方法1.1 核心函数解析1.2 基础实现模板1.3 整数版实现二、典型应用场景2

    Java进阶学习之如何开启远程调式

    《Java进阶学习之如何开启远程调式》Java开发中的远程调试是一项至关重要的技能,特别是在处理生产环境的问题或者协作开发时,:本文主要介绍Java进阶学习之如何开启远程调式的相关资料,需要的朋友... 目录概述Java远程调试的开启与底层原理开启Java远程调试底层原理JVM参数总结&nbsMbKKXJx

    Java深度学习库DJL实现Python的NumPy方式

    《Java深度学习库DJL实现Python的NumPy方式》本文介绍了DJL库的背景和基本功能,包括NDArray的创建、数学运算、数据获取和设置等,同时,还展示了如何使用NDArray进行数据预处理... 目录1 NDArray 的背景介绍1.1 架构2 JavaDJL使用2.1 安装DJL2.2 基本操

    C#使用DeepSeek API实现自然语言处理,文本分类和情感分析

    《C#使用DeepSeekAPI实现自然语言处理,文本分类和情感分析》在C#中使用DeepSeekAPI可以实现多种功能,例如自然语言处理、文本分类、情感分析等,本文主要为大家介绍了具体实现步骤,... 目录准备工作文本生成文本分类问答系统代码生成翻译功能文本摘要文本校对图像描述生成总结在C#中使用Deep

    Python中的随机森林算法与实战

    《Python中的随机森林算法与实战》本文详细介绍了随机森林算法,包括其原理、实现步骤、分类和回归案例,并讨论了其优点和缺点,通过面向对象编程实现了一个简单的随机森林模型,并应用于鸢尾花分类和波士顿房... 目录1、随机森林算法概述2、随机森林的原理3、实现步骤4、分类案例:使用随机森林预测鸢尾花品种4.1