建立没有数据集96准确性的辣胡椒分类器

2024-03-24 03:20

本文主要是介绍建立没有数据集96准确性的辣胡椒分类器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

数据科学 , 机器学习 (Data Science, Machine Learning)

In this article, I will create an AI capable of recognizing a spicy pepper from measurements and color. Because you won’t be able to find any dataset on the measurements of spicy peppers online, I will generate it myself using statistics methodologies. In a second article, I may try to apply regression algorithms to estimate the spiciness of your pepper on the Scoville Scale.

在本文中,我将创建一个能够通过测量和颜色识别辣辣椒的AI。 因为您将无法在线上找到任何关于辣辣椒测量的数据集,所以我将使用统计方法自行生成该数据集。 在第二篇文章中,我可能会尝试使用回归算法以Scoville量表估算您的胡椒的辛辣度。

处理: (Process:)

  1. Finding Available Data

    查找可用数据
  2. Making Measurements

    进行测量
  3. Creating the dataset from distributions

    从分布创建数据集
  4. Creating the Model

    创建模型
  5. Performance Evaluation

    绩效评估

1.查找可用数据 (1. Finding available data)

As mentioned before, you will unlikely find a dataset for everything you wish to build. In my case, I wanted to build a spicy pepper classifier, which is a difficult task if you have no data to start with. The only thing I could find on the internet was a comparison table of different spicy peppers (hopefully on the same scale).

如前所述,您不太可能找到要构建的所有内容的数据集。 就我而言,我想构建一个辣味分类器,如果没有任何数据开始,这将是一项艰巨的任务。 我在互联网上唯一能找到的是一张不同麻辣胡椒的比较表(希望是相同的比例)。

Image for post

I will need to transform this data into a digital one. What I can do is take measurements of these images and place them as features in a dataset.

我将需要将此数据转换为数字数据。 我所能做的就是对这些图像进行测量,并将它们作为特征放置在数据集中。

2.进行测量 (2. Making Measurements)

To make measurements I can use pixels. After knowing the rate of conversion of pixels to centimeters I can measure the size of each spicy pepper in pixels and convert it to its real-world scale.

为了进行测量,我可以使用像素。 在了解了像素到厘米的转换率之后,我可以测量每个香辛椒的大小(以像素为单位),并将其转换为现实世界的比例。

Image for post

This is the final table with all measurements (name, height, width, and color) converted into features.

这是最终表,其中所有度量(名称,高度,宽度和颜色)均已转换为特征。

#   measurements
pepper_measurements_px = [
['Anaheim', 262, 63, 'Green'],
['Cubanelle', 222, 70, 'Green'],
['Cayenne', 249, 22, 'Red'],
['Shishito', 140, 21, 'Green'],
['Hungarian Wax', 148, 63, 'Orange'],
['Jimmy Nardello', 190, 23, 'Red'],
['Fresno', 120, 43, 'Red'],
['Jalapeno', 106, 40, 'Dark Green'],
['Aji Amarillo', 92, 13, 'Yellow'],
['Aji Dulce', 81, 30, 'Red'],
['Serrano', 74, 14, 'Dark Green'],
['Padron', 62, 38, 'Dark Green'],
['Scotch Bonnet', 37, 42, 'Yellow'],
['Habanero', 67, 21, 'Orange'],
['Cumari', 18, 11, 'Yellow'],
]

I will now generate a dataset of 100.000 samples for spicy peppers.

现在,我将生成一个100.000个辛辣辣椒样本的数据集。

3.从分布创建数据集 (3. Creating datasets from distributions)

Before starting to create distributions, I will first need to convert the pixels into centimeters. Then for both length and width, I will need two separate normal distributions using this data as mean. For a standard deviation, I will use 10% of the mean (in this way I won’t have to Google the details of every spicy pepper).

在开始创建分布之前,我首先需要将像素转换为厘米。 然后,对于长度和宽度,我将需要使用此数据作为均值的两个单独的正态分布。 对于标准差,我将使用平均值的10%(这样,我就不必在Google上搜索每个辛辣胡椒的详细信息)。

创建功能 (Creating Functions)

I am creating a set of functions that will allow the creation of n datasets, inputting the size. I will use 100,000 samples for spicy pepper.

我正在创建一组函数,将允许创建n个数据集,并输入大小。 我将用100,000个样本制作辣胡椒。

#simulated probability distribution of one stock
from scipy.stats import skewnorm
import matplotlib.pyplot as plt
import pandas as pd
import numpy as npdef create_peppers(sd, mean, alfa, size):
#invertire il segno di alfa
x = skewnorm.rvs(-alfa, size=size)
def calc(k, sd, mean):
return (k*sd)+mean
x = calc(x, sd, mean) #standard distribution#graph the distribution
#pd.DataFrame(x).hist(bins=100)#pick one random number from the distribution
#formally I would use cdf, but I just have to pick randomly from the 1000000 samples
df = [np.random.choice(x) for k in range(size)]
#return the DataFrame
return pd.DataFrame(df)def cm_converter(px_measurements):
pc_cm = 0.05725
for _ in range(len(px_measurements)):
px_measurements[_][1] *= pc_cm
px_measurements[_][2] *= pc_cm
return px_measurements

创建数据集 (Creating the Dataset)

I am now ready to create the datasets. I can specify the use of the 10% of the mean as a standard deviation (I can easily change it from height_sd and widht_sd):

我现在准备创建数据集。 我可以指定使用平均值的10%作为标准偏差(我可以很容易地从height_sd和widht_sd进行更改):

#   create converted list
pepper_measurements_cm = cm_converter(pepper_measurements_px)# create final datasets
heigh_sd = 0.1
width_sd = 0.1df = pd.DataFrame()
for _ in pepper_measurements_cm:
# create height
#SD is 10% of the height
df_height = create_peppers(_[1]*heigh_sd, _[1], 0, 100000)
# create width
#SD is 10% of the width
df_width = create_peppers(_[2]*width_sd, _[2], 0, 100000)
#create DataFrame
df_single = pd.concat([df_height, df_width], axis=1)
df_single.columns = ['height', 'width']
#create name
df_single['name'] = str(_[0])
df_single['color'] = str(_[3])df = pd.concat([df, df_single], axis=0)
df
Image for post
Normal distribution of a single generated feature
单个生成特征的正态分布

This is the final result: combined, the dataset counts 1.5 Million samples:

这是最终结果:合并后,数据集计数了150万个样本:

Image for post
Final Dataset
最终数据集

If we plot height and width in different histograms:

如果我们在不同的直方图中绘制高度和宽度:

Image for post
height and width in separated histograms
分开的直方图中的高度和宽度

4.创建模型 (4. Creating the Model)

The model I will be using is a Naive Bayes Classifier. Rather than many other models, this one is specialized with data that:

我将使用的模型是朴素贝叶斯分类器。 而不是许多其他模型,该模型专用于以下数据:

  • Is independent

    是独立的
  • Follows a normal distribution

    服从正态分布

Because I built my dataset following these presuppositions, this classifier is perfect for what I wish to build.

因为我是按照这些前提建立数据集的,所以该分类器非常适合我要构建的内容。

前处理 (Preprocessing)

The only preprocessing step I will have to make is encoding the color with a one_hot encoding algorithm:

我唯一要做的预处理步骤是使用one_hot编码算法对颜色进行编码:

#backup
X = df.copy()def one_hot(df, partitions):
#togliamo le colonne da X
for col in partitions:
k = df.pop(col)
k = pd.get_dummies(k, prefix=col)
df = pd.concat([df, k] , axis=1)
return dfX = one_hot(X, ['color'])
X

选择功能和标签 (Selecting Features and Labels)

y = X.pop('name')
y
Image for post
Labels
标签
X
Image for post
Features after one_hot encoding
one_hot编码后的功能

分裂 (Splitting)

from sklearn.model_selection import train_test_splitX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

I will now split Features and Labels randomly, a ratio of 80:20 will suffice.

现在,我将随机分割特征和标签,比率为80:20就足够了。

训练模型 (Training the Model)

from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X_train, y_train)

The model has been trained:

该模型已经过训练:

GaussianNB(priors=None, var_smoothing=1e-09)

5.绩效评估 (5. Performance Evaluation)

After training the model, I will test it on the part of the dataset which the AI has never seen during training:

训练完模型后,我将在AI在训练过程中从未见过的数据集部分进行测试:

clf.score(X_test, y_test, sample_weight=None)
0.9659133333333333

The model has reached an outstanding 96% accuracy!

该模型达到了出色的96%精度!

翻译自: https://medium.com/towards-artificial-intelligence/building-a-spicy-pepper-classifier-with-no-datasets-96-accuracy-8262d54a8117


http://www.taodudu.cc/news/show-8503898.html

相关文章:

  • Effective Python -- 第 1 章 用 Pythonic 方式来思考(下)
  • 每日10行代码90:编写高质量python代码方法7——用列表推导来取代map和filter
  • Effective Python学习笔记
  • 读书笔记:《Effective Python 编写高质量Python代码的59个有效方法》
  • 大数据导论学习日志
  • 大数据的时代,迈向人类的未来
  • 联想大数据企业级分析平台(LEAP)通过数据中心联盟认证
  • 联想大数据入选工信部国家“大数据优秀产业、服务和应用解决方案”
  • 联想大数据,与吴静钰一起拼搏
  • [bzoj] 牡牛和牝牛 题解
  • acwing数论
  • 长春网站建设公司哪家好?
  • 做网站建设前的准备
  • 做网站建设需要注意的五大事项
  • 做网站建设前需要了解的几个问题
  • 靠谱的建网站公司,才能保证网站的安全
  • 做网站建设推广的团队或公司不挣钱的原因
  • 如何在做网站建设时为优化助力
  • 关于网站建设公司哪家好的一些事
  • 蚂蚁全媒体刘鑫炜解答:你们觉得当下公司做网站建设有必要性吗?
  • Vue2.js工程实践4:Vue相关开源项目库汇总
  • 系统分析---作业6
  • 2029中国电影市场前瞻:大数据审查、区块链宣发、5G一秒同步拷贝
  • 前后端分离nodejs和vue.js电影院在线售票系统
  • Paython实操印章图片 自动抠动
  • vue2 之 实现pdf电子签章
  • 推荐 15 款很棒的文本编辑器
  • css 设置span标签单行文字展示
  • Css实现单行文字水平居中多行文字左对齐
  • AutoLisp 获得选中的单行文字的内容
  • 这篇关于建立没有数据集96准确性的辣胡椒分类器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



    http://www.chinasem.cn/article/840312

    相关文章

    【服务器运维】MySQL数据存储至数据盘

    查看磁盘及分区 [root@MySQL tmp]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical)

    Eureka高可用注册中心registered-replicas没有分布式注册中心

    自己在学习过程中发现,如果Eureka挂掉了,其他的Client就跑不起来了,那既然是商业项目,还是要处理好这个问题,所以决定用《Spring Cloud微服务实战》(PDF版在全栈技术交流群中自行获取)中说的“高可用注册中心”。 一开始我yml的配置是这样的 server:port: 8761eureka:instance:hostname: 127.0.0.1client:fetch-r

    SQL Server中,查询数据库中有多少个表,以及数据库其余类型数据统计查询

    sqlserver查询数据库中有多少个表 sql server 数表:select count(1) from sysobjects where xtype='U'数视图:select count(1) from sysobjects where xtype='V'数存储过程select count(1) from sysobjects where xtype='P' SE

    数据时代的数字企业

    1.写在前面 讨论数据治理在数字企业中的影响和必要性,并介绍数据治理的核心内容和实践方法。作者强调了数据质量、数据安全、数据隐私和数据合规等方面是数据治理的核心内容,并介绍了具体的实践措施和案例分析。企业需要重视这些方面以实现数字化转型和业务增长。 数字化转型行业小伙伴可以加入我的星球,初衷成为各位数字化转型参考库,星球内容每周更新 个人工作经验资料全部放在这里,包含数据治理、数据要

    如何在Java中处理JSON数据?

    如何在Java中处理JSON数据? 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天我们将探讨在Java中如何处理JSON数据。JSON(JavaScript Object Notation)作为一种轻量级的数据交换格式,在现代应用程序中被广泛使用。Java通过多种库和API提供了处理JSON的能力,我们将深入了解其用法和最佳

    两个基因相关性CPTAC蛋白组数据

    目录 蛋白数据下载 ①蛋白数据下载 1,TCGA-选择泛癌数据  2,TCGA-TCPA 3,CPTAC(非TCGA) ②蛋白相关性分析 1,数据整理 2,蛋白相关性分析 PCAS在线分析 蛋白数据下载 CPTAC蛋白组学数据库介绍及数据下载分析 – 王进的个人网站 (jingege.wang) ①蛋白数据下载 可以下载泛癌蛋白数据:UCSC Xena (xena

    BD错误集锦5——java.nio.file.FileSystemException 客户端没有所需的特权

    问题:在运行storm本地模式程序时,java.nio.file.FileSystemException  客户端没有所需的特权   解决方式:以管理员身份运行IDEA即可。

    中国341城市生态系统服务价值数据集(2000-2020年)

    生态系统服务反映了人类直接或者间接从自然生态系统中获得的各种惠益,对支撑和维持人类生存和福祉起着重要基础作用。目前针对全国城市尺度的生态系统服务价值的长期评估还相对较少。我们在Xie等(2017)的静态生态系统服务当量因子表基础上,选取净初级生产力,降水量,生物迁移阻力,土壤侵蚀度和道路密度五个变量,对生态系统供给服务、调节服务、支持服务和文化服务共4大类和11小类的当量因子进行了时空调整,计算了

    【计算机网络篇】数据链路层(12)交换机式以太网___以太网交换机

    文章目录 🍔交换式以太网🛸以太网交换机 🍔交换式以太网 仅使用交换机(不使用集线器)的以太网就是交换式以太网 🛸以太网交换机 以太网交换机本质上就是一个多接口的网桥: 交换机的每个接口考研连接计算机,也可以理解集线器或另一个交换机 当交换机的接口与计算机或交换机连接时,可以工作在全双工方式,并能在自身内部同时连通多对接口,使每一对相互通信的计算机都能像