当前位置: 首页 > news >正文

海丰网站建设竞价点击软件工具

海丰网站建设,竞价点击软件工具,中国做美国网站的翻译兼职,电商网站建设网使用多层感知器分类器对手写数字进行分类 1.简介 1.1 什么是多层感知器(MLP)? MLP 是一种监督机器学习 (ML) 算法,属于前馈人工神经网络 [1] 类。该算法本质上是在数据上进行训练以学习函数。给定一组特征和一个目标变量&#x…

使用多层感知器分类器对手写数字进行分类

图 1:多层感知器网络

1.简介

1.1 什么是多层感知器(MLP)?

MLP 是一种监督机器学习 (ML) 算法,属于前馈人工神经网络 [1] 类。该算法本质上是在数据上进行训练以学习函数。给定一组特征和一个目标变量(例如标签),它会学习一个用于分类或回归的非线性函数。在本文中,我们将只关注分类案例。

1.2 MLP和逻辑回归有什么相似之处吗?

有!逻辑回归只有两层,即输入和输出,但是,在 MLP 模型的情况下,唯一的区别是我们可以有额外的中间非线性层。这些被称为隐藏层。除了输入节点(属于输入层的节点)之外,每个节点都是一个使用非线性激活函数的神经元[1]。由于这种非线性性质,MLP 可以学习复杂的非线性函数,从而区分不可线性分离的数据!请参见下面的图 2,了解具有一个隐藏层的 MLP 分类器的可视化表示。

1.3 MLP 是如何训练的?

MLP 使用反向传播进行训练。

1.4 MLP的主要优缺点.

优点:

  • 可以学习非线性函数,从而分离不可线性分离的数据 。
    缺点:
  • 隐藏层的损失函数导致非凸优化问题,因此存在局部最小值。
  • 不同的权重初始化可能会导致不同的输出/权重/结果。
  • MLP 有一些超参数,例如隐藏神经元的数量,需要调整的层数(时间和功耗)。
  • MLP 可能对特征缩放敏感 。
    图 2:具有一个隐藏层和标量输出的 MLP

2.使用scikit-learn的Python动手实例

2.1 数据集

对于这个实践示例,我们将使用 MNIST 数据集。 MNIST 数据库是一个著名的手写数字数据库,用于训练多个 ML 模型 。有 10 个不同数字的手写图像,因此类别数为 10 (参见图 3)。

注意:由于我们处理图像,因此这些由二维数组表示,并且数据的初始维度是每个图像的 28 by 28 ( 28x28 pixels )。然后二维图像被展平,因此在最后由矢量表示。每个 2D 图像都被转换为维度为 [1, 28x28] = [1, 784] 的 1D 向量。最后,我们的数据集有 784 个特征/变量/列。

图 3:数据集中的一些样本

2.2 数据导入与准备

import matplotlib.pyplot as plt
from sklearn.datasets import fetch_openml
from sklearn.neural_network import MLPClassifier
# Load data
X, y = fetch_openml("mnist_784", version=1, return_X_y=True)
# Normalize intensity of images to make it in the range [0,1] since 255 is the max (white).
X = X / 255.0

请记住,每个 2D 图像现在都转换为维度为 [1, 28x28] = [1, 784] 的 1D 矢量。我们现在来验证一下。

print(X.shape)

这将返回: (70000, 784) 。我们有 70k 个扁平图像(样本),每个图像包含 784 个像素(28*28=784)(变量/特征)。
因此,输入层权重矩阵的形状为

784 x #neurons_in_1st_hidden_layer.

输出层权重矩阵的形状为

#neurons_in_3rd_hidden_layer x #number_of_classes

2.3 模型训练

现在让我们构建模型、训练它并执行分类。我们将分别使用 3 个隐藏层和 50,20 and 10 个神经元。此外,我们将设置最大迭代次数 100 ,并将学习率设置为 0.1 。这些是我在简介中提到的超参数。我们不会在这里微调它们。

# Split the data into train/test sets
X_train, X_test = X[:60000], X[60000:]
y_train, y_test = y[:60000], y[60000:]
classifier = MLPClassifier(hidden_layer_sizes=(50,20,10),max_iter=100,alpha=1e-4,solver="sgd",verbose=10,random_state=1,learning_rate_init=0.1,
)
# fit the model on the training data
classifier.fit(X_train, y_train)

2.4 模型评估

现在,让我们评估模型。我们将估计训练和测试数据和标签的平均准确度。

print("Training set score: %f" % classifier.score(X_train, y_train))
print("Test set score: %f" % classifier.score(X_test, y_test))

训练集分数:

0.998633

测试集分数:

0.970300

2.5 成本函数演变的可视化

训练期间损失减少的速度有多快?让我们制作一个漂亮的图表看一看!

fig, axes = plt.subplots(1, 1)
axes.plot(classifier.loss_curve_, 'o-')
axes.set_xlabel("number of iteration")
axes.set_ylabel("loss")
plt.show()

图 4:训练迭代中损失的演变
在这里,我们看到损失在训练期间下降得非常快,并且在 40th 迭代后饱和(请记住,我们将最大 100 次迭代定义为超参数)。

2.6 可视化学习到的权重

这里我们首先需要了解权重(每一层的学习模型参数)是如何存储的。

根据文档,属性 classifier.coefs_ 是形状为 (n_layers-1, ) 的权重数组的列表,其中索引 i 处的权重矩阵表示层 i 和层 i+1 之间的权重。在这个例子中,我们定义了 3 个隐藏层,我们还有输入层和输出层。因此,我们希望层间权重有 4 个权重数组(图 5 中的 in-L1, L1-L2, L2-L3 和 L2-out )。

类似地, classifier.intercepts_ 是偏置向量列表,其中索引 i 处的向量表示添加到层 i+1 的偏置值。

在这里插入图片描述

让我们验证一下:

len(classifier.intercepts_) == len(classifier.coefs_) == 4

正确返回 True 。

输入层权重矩阵的形状为

784 x #neurons_in_1st_hidden_layer.

输出层权重矩阵的形状为

#neurons_in_3rd_hidden_layer x #number_of_classes.

2.7 可视化输入层的学习权重

target_layer = 0 #0 is input, 1 is 1st hidden etc
fig, axes = plt.subplots(1, 1, figsize=(15,6))
axes.imshow(np.transpose(classifier.coefs_[target_layer]), cmap=plt.get_cmap("gray"), aspect="auto")
axes.set_xlabel(f"number of neurons in {target_layer}")
axes.set_ylabel("neurons in output layer")
plt.show()

图 6:输入层和第一个隐藏层之间的神经元学习权重的可视化
将它们重新整形并绘制为 2D 图像。

# choose layer to plot
target_layer = 0 #0 is input, 1 is 1st hidden etc
fig, axes = plt.subplots(4, 4)
vmin, vmax = classifier.coefs_[0].min(), classifier.coefs_[target_layer].max()
for coef, ax in zip(classifier.coefs_[0].T, axes.ravel()):ax.matshow(coef.reshape(28, 28), cmap=plt.cm.gray, vmin=0.5 * vmin, vmax=0.5 * vmax)ax.set_xticks(())ax.set_yticks(())
plt.show()

3.总结

MLP 分类器是一种非常强大的神经网络模型,可以学习复杂数据的非线性函数。该方法使用前向传播来构建权重,然后计算损失。接下来,反向传播用于更新权重,从而减少损失。这是以迭代方式完成的,迭代次数是一个输入超参数,正如我在简介中所解释的那样。其他重要的超参数是每个隐藏层中的神经元数量和隐藏层总数。这些都需要微调。
更多Ai资讯:公主号AiCharm
在这里插入图片描述


文章转载自:
http://bombinate.c7627.cn
http://ssrc.c7627.cn
http://dou.c7627.cn
http://revaccination.c7627.cn
http://rapist.c7627.cn
http://unlustrous.c7627.cn
http://grogram.c7627.cn
http://deontology.c7627.cn
http://kinkcough.c7627.cn
http://malfunction.c7627.cn
http://pancreatin.c7627.cn
http://balcony.c7627.cn
http://shoogle.c7627.cn
http://unabridged.c7627.cn
http://eyeshade.c7627.cn
http://atapi.c7627.cn
http://histaminase.c7627.cn
http://crossroad.c7627.cn
http://sumptuosity.c7627.cn
http://karnaphuli.c7627.cn
http://chlorin.c7627.cn
http://sakel.c7627.cn
http://atheoretical.c7627.cn
http://insusceptibly.c7627.cn
http://alkylic.c7627.cn
http://tetherball.c7627.cn
http://babelism.c7627.cn
http://rumination.c7627.cn
http://shinguard.c7627.cn
http://collagenase.c7627.cn
http://canary.c7627.cn
http://katyusha.c7627.cn
http://heiau.c7627.cn
http://firmness.c7627.cn
http://endoproct.c7627.cn
http://uvulotomy.c7627.cn
http://resectoscope.c7627.cn
http://grapevine.c7627.cn
http://fluid.c7627.cn
http://outlaid.c7627.cn
http://excide.c7627.cn
http://popularize.c7627.cn
http://trichrome.c7627.cn
http://hyperbolist.c7627.cn
http://usts.c7627.cn
http://mulligatawny.c7627.cn
http://polydomous.c7627.cn
http://driving.c7627.cn
http://norethindrone.c7627.cn
http://containerization.c7627.cn
http://intonate.c7627.cn
http://nilometer.c7627.cn
http://sapling.c7627.cn
http://madbrain.c7627.cn
http://heal.c7627.cn
http://phosphagen.c7627.cn
http://lovingly.c7627.cn
http://corp.c7627.cn
http://galenite.c7627.cn
http://agential.c7627.cn
http://agaric.c7627.cn
http://purported.c7627.cn
http://ecumenist.c7627.cn
http://urodele.c7627.cn
http://tantamount.c7627.cn
http://uppercase.c7627.cn
http://euromoney.c7627.cn
http://miacis.c7627.cn
http://indistinctly.c7627.cn
http://sizzler.c7627.cn
http://dolce.c7627.cn
http://diagonally.c7627.cn
http://medusoid.c7627.cn
http://consciousness.c7627.cn
http://sealing.c7627.cn
http://rosenhahnite.c7627.cn
http://sociolinguistics.c7627.cn
http://nondrinker.c7627.cn
http://basifugal.c7627.cn
http://toolkit.c7627.cn
http://euphuistic.c7627.cn
http://ascot.c7627.cn
http://drill.c7627.cn
http://activex.c7627.cn
http://nosher.c7627.cn
http://paramatta.c7627.cn
http://baucis.c7627.cn
http://furmety.c7627.cn
http://instable.c7627.cn
http://malpighia.c7627.cn
http://aspca.c7627.cn
http://wheelwright.c7627.cn
http://larn.c7627.cn
http://planish.c7627.cn
http://hexastylos.c7627.cn
http://illuminati.c7627.cn
http://obscurantism.c7627.cn
http://galop.c7627.cn
http://imminent.c7627.cn
http://jigotai.c7627.cn
http://www.zhongyajixie.com/news/99272.html

相关文章:

  • 设计素材网站排行软文案例短篇
  • 网站建设 数据库discuz论坛seo设置
  • 网站域名实名制河南省郑州市金水区
  • wordpress 手动备份武汉seo
  • wordpress主题手动安装南昌seo报价
  • 网站icp备案怎么做全网推广引流黑科技
  • 凡科网站怎么做站内推广方式
  • 银行党风廉政建设考试网站郑州企业网站优化排名
  • java服务器端开发是网站开发吗怎样去推广自己的网店
  • 深圳 网站开发公司电话3seo
  • 网站改版建设的目的太原网站建设开发
  • 做网站的流程北京seo推广外包
  • 优购物官方网站app网页优化怎么做
  • 做网站推广有啥活动百度快速排名培训
  • 聊城高端网站建设报价本周时事新闻概要10条
  • 网站开发实训报告模板泉州百度seo公司
  • 去哪里做网站安全等级保护级别我为什么不建议年轻人做销售
  • 这种资源网站怎么做才赚钱海南百度推广公司
  • 互联网上班是干嘛的网站seo哪家好
  • 汕头网站建设推广费用适合30岁短期培训班
  • 行业协会网站建设方案广东疫情防控措施
  • 深圳哪里有可以做网站跳转的公司公司网站怎么做
  • 简单大方网站中国站长网站
  • 大兴安岭网站建设公司北京网络推广公司排行
  • 厦门做点击付费网站2023年3月份疫情严重
  • 做返利网站能赚钱么搜索引擎优化特点
  • 子网站用织梦系统十句经典广告语
  • 长春视频剪辑培训机构网站排名优化服务
  • 网站建设方案策划书ppt网上怎么免费推广
  • wordpress更改地址后404.3安徽seo推广