pybrain_PyBrain-快速指南

pybrain

pybrain

PyBrain-快速指南 (PyBrain - Quick Guide)

PyBrain-概述 (PyBrain - Overview)

Pybrain is an open-source library for Machine learning implemented using python. The library offers you some easy to use training algorithms for networks, datasets, trainers to train and test the network.

Pybrain是使用python实现的用于机器学习的开源库。 该库为您提供了一些易于使用的网络,数据集,培训师来训练和测试网络的培训算法。

Definition of Pybrain as put by its official documentation is as follows −

官方文件对Pybrain的定义如下-

PyBrain is a modular Machine Learning Library for Python. Its goal is to offer flexible, easy-to-use yet still powerful algorithms for Machine Learning Tasks and a variety of predefined environments to test and compare your algorithms.

PyBrain是用于Python的模块化机器学习库。 它的目标是为机器学习任务和各种预定义环境提供灵活,易于使用但仍功能强大的算法,以测试和比较您的算法。

PyBrain is short for Python-Based Reinforcement Learning, Artificial Intelligence, and Neural Network Library. In fact, we came up with the name first and later reverse-engineered this quite descriptive "Backronym".

PyBrain是基于Python的强化学习,人工智能和神经网络库的缩写。 实际上,我们首先想出了这个名称,后来又对这个描述性很强的“ Backronym”进行了反向工程。

裂脑的特征 (Features of Pybrain)

The following are the features of Pybrain −

以下是Pybrain的功能-

网路 (Networks)

A network is composed of modules and they are connected using connections. Pybrain supports neural networks like Feed-Forward Network, Recurrent Network, etc.

网络由模块组成,它们通过连接进行连接。 Pybrain支持神经网络,例如前馈网络,递归网络等。

feed-forward network is a neural network, where the information between nodes moves in the forward direction and will never travel backward. Feed Forward network is the first and the simplest one among the networks available in the artificial neural network.

前馈网络是一个神经网络,节点之间的信息向前移动,永远不会向后移动。 前馈网络是人工神经网络中可用的网络中的第一个和最简单的网络。

The information is passed from the input nodes, next to the hidden nodes and later to the output node.

信息从输入节点传递到隐藏节点之后,再传递到输出节点。

Recurrent Networks are similar to Feed Forward Network; the only difference is that it has to remember the data at each step. The history of each step has to be saved.

循环网络类似于前馈网络; 唯一的区别是它必须记住每个步骤中的数据。 必须保存每个步骤的历史记录。

数据集 (Datasets)

Datasets is the data to be given to test, validate and train on networks. The type of dataset to be used depends on the tasks that we are going to do with Machine Learning. The most commonly used datasets that Pybrain supports are SupervisedDataSet and ClassificationDataSet.

数据集是要在网络上测试,验证和训练的数据。 使用的数据集类型取决于我们将要与机器学习一起完成的任务。 Pybrain支持的最常用的数据集是SupervisedDataSetClassificationDataSet

SupervisedDataSet − It consists of fields of input and target. It is the simplest form of a dataset and mainly used for supervised learning tasks.

SupervisedDataSet-它由输入目标字段组成。 它是数据集的最简单形式,主要用于监督学习任务。

ClassificationDataSet − It is mainly used to deal with classification problems. It takes in input, target field and also an extra field called "class" which is an automated backup of the targets given. For example, the output will be either 1 or 0 or the output will be grouped together with values based on input given, i.e., either it will fall in one particular class.

分类数据集 -主要用于处理分类问题。 它接受inputtarget字段以及一个称为“ class”的额外字段,该字段是给定目标的自动备份。 例如,输出将为1或0,或者将根据给定的输入将值与值分组在一起,即,它将属于一个特定类别。

培训师 (Trainer)

When we create a network, i.e., neural network, it will get trained based on the training data given to it. Now whether the network is trained properly or not will depend on the prediction of test data tested on that network. The most important concept in Pybrain Training is the use of BackpropTrainer and TrainUntilConvergence.

当我们创建一个网络(即神经网络)时,它将根据提供给它的训练数据进行训练。 现在,是否对网络进行适当的培训将取决于对该网络上测试的测试数据的预测。 Pybrain培训中最重要的概念是使用BackpropTrainer和TrainUntilConvergence。

BackpropTrainer − It is a trainer that trains the parameters of a module according to a supervised or ClassificationDataSet dataset (potentially sequential) by backpropagating the errors (through time).

BackpropTrainer-这是一个训练器,通过对错误(在整个时间范围内)进行反向传播,根据受监管的或CategoryDataSet数据集(可能是顺序的)训练模块的参数。

TrainUntilConvergence −It is used to train the module on the dataset until it converges.

TrainUntilConvergence-用于训练数据集中的模块直至收敛。

工具类 (Tools)

Pybrain offers tools modules which can help to build a network by importing package: pybrain.tools.shortcuts.buildNetwork

Pybrain提供的工具模块可通过导入软件包来帮助构建网络: pybrain.tools.shortcuts.buildNetwork

可视化 (Visualization)

The testing data cannot be visualized using pybrain. But Pybrain can work with other frameworks like Mathplotlib, pyplot to visualize the data.

使用pybrain无法显示测试数据。 但是Pybrain可以与Mathplotlib,pyplot等其他框架一起使用以可视化数据。

Pybrain的优点 (Advantages of Pybrain)

The advantages of Pybrain are −

Pybrain的优点是-

  • Pybrain is an open-source free library to learn Machine Learning. It is a good start for any newcomer interested in Machine Learning.

    Pybrain是学习机器学习的开源免费库。 对于任何对机器学习感兴趣的新手来说,这都是一个好的开始。

  • Pybrain uses python to implement it and that makes it fast in development in comparison to languages like Java/C++.

    Pybrain使用python来实现它,与Java / C ++之类的语言相比,Pybrain使它的开发速度更快。

  • Pybrain works easily with other libraries of python to visualize data.

    Pybrain可与其他python库轻松协作以可视化数据。

  • Pybrain offers support for popular networks like Feed-Forward Network, Recurrent Networks, Neural Networks, etc.

    Pybrain支持流行的网络,例如前馈网络,循环网络,神经网络等。

  • Working with .csv to load datasets is very easy in Pybrain. It also allows using datasets from another library.

    在Pybrain中,使用.csv加载数据集非常容易。 它还允许使用另一个库中的数据集。

  • Training and testing of data are easy using Pybrain trainers.

    使用Pybrain培训师可以轻松地对数据进行培训和测试。

Pybrain的局限性 (Limitations of Pybrain)

Pybrain offers less help for any issues faced. There are some queries unanswered on stackoverflow and on Google Group.

Pybrain对于遇到的任何问题提供的帮助较少。 在stackoverflowGoogle Group上,有些查询没有答案。

Pybrain的工作流程 (Workflow of Pybrain)

As per Pybrain documentation the flow of machine learning is shown in the following figure −

根据Pybrain文档,机器学习的流程如下图所示-

Workflow Of Pybrain

At the start, we have raw data which after preprocessing can be used with Pybrain.

首先,我们有原始数据,经过预处理后可以与Pybrain一起使用。

The flow of Pybrain starts with datasets which are divided into trained and test data.

Pybrain的流程始于将数据集分为训练和测试数据。

  • the network is created, and the dataset and the network are given to the trainer.

    创建网络,并将数据集和网络提供给培训师。

  • the trainer trains the data on the network and classifies the outputs as trained error and validation error which can be visualized.

    培训师在网络上训练数据并将输出分类为可以显示的训练错误和验证错误。

  • the tested data can be validated to see if the output matches the trained data.

    可以验证测试数据,以查看输出是否与训练数据匹配。

术语 (Terminology)

There are important terms to be considered while working with Pybrain for machine learning. They are as follows −

与Pybrain合作进行机器学习时,需要考虑一些重要术语。 它们如下-

Total Error − It refers to the error shown after the network is trained. If the error keeps changing on every iteration, it means it still needs time to settle, until it starts showing a constant error between iteration. Once it starts showing the constant error numbers, it means that the network has converged and will remain the same irrespective of any additional training is applied.

总错误 -指的是在训练网络后显示的错误。 如果错误在每次迭代中都在不断变化,则意味着它仍然需要时间来解决,直到在迭代之间开始显示恒定错误为止。 一旦开始显示恒定的错误号,就意味着网络已经收敛,并且将保持不变,无论是否应用了任何其他培训。

Trained data − It is the data used to train the Pybrain network.

训练后的数据 -这是用于训练Pybrain网络的数据。

Testing data − It is the data used to test the trained Pybrain network.

测试数据 -这是用于测试经过训练的Pybrain网络的数据。

Trainer − When we create a network, i.e., neural network, it will get trained based on the training data given to it. Now whether the network is trained properly or not will depend on the prediction of test data tested on that network. The most important concept in Pybrain Training is the use of BackpropTrainer and TrainUntilConvergence.

培训师 -当我们创建一个网络(即神经网络)时,它将根据提供给它的培训数据进行培训。 现在,是否对网络进行适当的培训将取决于对该网络上测试的测试数据的预测。 Pybrain培训中最重要的概念是使用BackpropTrainer和TrainUntilConvergence。

BackpropTrainer − It is a trainer that trains the parameters of a module according to a supervised or ClassificationDataSet dataset (potentially sequential) by backpropagating the errors (through time).

BackpropTrainer-这是一个训练器,通过对错误(在整个时间范围内)进行反向传播,根据受监管的或CategoryDataSet数据集(可能是顺序的)训练模块的参数。

TrainUntilConvergence − It is used to train the module on the dataset until it converges.

TrainUntilConvergence-用于在数据集中训练模块直至收敛。

Layers − Layers are basically a set of functions that are used on hidden layers of a network.

-层基本上是在网络的隐藏层上使用的一组功能。

Connections − A connection works similar to a layer; an only difference is that it shifts the data from one node to the other in a network.

连接 -连接的工作方式类似于图层; 唯一的区别是它将数据从网络中的一个节点转移到另一个节点。

Modules − Modules are networks which consists of input and output buffer.

模块 -模块是由输入和输出缓冲区组成的网络。

Supervised Learning − In this case, we have an input and output, and we can make use of an algorithm to map the input with the output. The algorithm is made to learn on the training data given and iterated on it and the process of iteration stops when the algorithm predicts the correct data.

监督学习 -在这种情况下,我们有一个输入和输出,我们可以利用一种算法将输入与输出进行映射。 使该算法学习给定的训练数据并对其进行迭代,并且当算法预测正确的数据时,迭代过程将停止。

Unsupervised − In this case, we have input but don't know the output. The role of unsupervised learning is to get trained as much as possible with the data given.

无人监督 -在这种情况下,我们有输入但不知道输出。 无监督学习的作用是利用给定的数据尽可能地接受训练。

PyBrain-环境设置 (PyBrain - Environment Setup)

In this chapter, we will work on the installation of PyBrain. To start working with PyBrain, we need to install Python first. So we are going to work on following −

在本章中,我们将进行PyBrain的安装。 要开始使用PyBrain,我们需要先安装Python。 所以我们将继续努力-

  • Install Python

    安装Python
  • Install PyBrain

    安装PyBrain

安装Python (Installing Python)

To install Python, go to the Python official site: www.python.org/downloads as shown below and click on the latest version available for windows, Linux/Unix and macOS. Download Python as per your 64- or 32-bit OS available with you.

要安装Python,请访问Python官方网站: www.python.org/downloads ,如下所示,然后单击可用于Windows,Linux / Unix和macOS的最新版本。 根据您可用的64位或32位操作系统下载Python。

Installing Python

Once you have downloaded, click on the .exe file and follow the steps to install python on your system.

下载完成后,点击.exe文件,然后按照以下步骤在系统上安装python。

Setup Progress

The python package manager, i.e., pip will also get installed by default with the above installation. To make it work globally on your system, directly add the location of python to the PATH variable, the same is shown at the start of the installation to remember to check the checkbox which says ADD to PATH. In case you forget to check it please follow the below given steps to add to PATH.

python软件包管理器,即pip也会默认安装上述安装。 要使其在系统上全局运行,请将python的位置直接添加到PATH变量中,安装开始时会显示相同的位置,以记住选中添加到PATH复选框。 如果您忘记检查,请按照以下给定步骤添加到PATH。

添加到PATH (Add to PATH)

To add to PATH, follow the below steps −

要添加到PATH,请执行以下步骤-

  • Right-click on your Computer icon and click on properties -> Advanced System Settings.

    右键单击您的计算机图标,然后单击属性->高级系统设置。

  • It will display the screen as shown below

    它将显示如下屏幕

System Properties
  • Click on Environment Variables as shown above. It will display the screen as shown below

    单击上面显示的环境变量。 它将显示如下屏幕

Environment Variables

Select Path and click on Edit button, add the location path of your python at the end. Now let us check the python version.

选择“路径”,然后单击“编辑”按钮,最后添加python的位置路径。 现在让我们检查python版本。

检查Python版本 (Checking for Python version)

The below code helps us in checking the version of Python −

以下代码可帮助我们检查Python版本-


E:\pybrain>python --version
Python 3.7.3

安装PyBrain (Installing PyBrain)

Now that we have installed Python, we are going to install Pybrain. Clone the pybrain repository as shown below −

现在我们已经安装了Python,我们将安装Pybrain。 克隆pybrain存储库,如下所示-


git clone git://github.com/pybrain/pybrain.git


C:\pybrain>git clone git://github.com/pybrain/pybrain.git
Cloning into 'pybrain'...
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 12177 (delta 0), reused 0 (delta 0), pack-reused 12175
Receiving objects: 100% (12177/12177), 13.29 MiB | 510.00 KiB/s, done.
Resolving deltas: 100% (8506/8506), done.

Now perform cd pybrain and run following command −

现在执行cd pybrain并运行以下命令-


python setup.py install

This command will install pybrain on your system.

此命令将在您的系统上安装pybrain。

Once done, to check if pybrain is installed or not, open command line prompt and start the python interpreter as shown below −

完成后,要检查是否安装了pybrain,请打开命令行提示符并启动python解释器,如下所示-


C:\pybrain\pybrain>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

We can add import pybrain using the below code −

我们可以使用以下代码添加导入pybrain-


>>> import pybrain
>>>

If the import pybrain works without any errors, it means pybrain in installed successfully. You can now write your code to start working with pybrain.

如果导入pybrain正常运行,则表示pybrain已成功安装。 现在,您可以编写代码以开始使用pybrain。

PyBrain-PyBrain网络简介 (PyBrain - Introduction to PyBrain Networks)

PyBrain is a library developed for Machine Learning with Python. There are some important concepts in Machine Learning and one among them is Networks. A network is composed of modules and they are connected using connections.

PyBrain是为使用Python进行机器学习而开发的库。 机器学习中有一些重要的概念,其中之一就是网络。 网络由模块组成,它们通过连接进行连接。

A layout of a simple neural network is as follows −

一个简单的神经网络的布局如下-

Simple Neural Network

Pybrain supports neural networks such as Feed-Forward Network, Recurrent Network, etc.

Pybrain支持神经网络,例如前馈网络,递归网络等。

A feed-forward network is a neural network, where the information between nodes moves in the forward direction and will never travel backward. Feed Forward network is the first and the simplest one among the networks available in the artificial neural network. The information is passed from the input nodes, next to the hidden nodes and later to the output node.

前馈网络是一个神经网络,其中节点之间的信息沿向前方向移动,并且永远不会向后传播。 前馈网络是人工神经网络中可用的网络中的第一个和最简单的网络。 信息从输入节点传递到隐藏节点之后,再传递到输出节点。

Here is a simple feed forward network layout.

这是一个简单的前馈网络布局。

Feed Forward Network

The circles are said to be modules and the lines with arrows are connections to the modules.

圆圈是模块,带有箭头的线是与模块的连接。

The nodes A, B, C and D are input nodes

节点ABCD是输入节点

H1, H2, H3, H4 are hidden nodes and O is the output.

H1H2H3H4是隐藏节点,O是输出。

In the above network, we have 4 input nodes, 4 hidden layers and 1 output. The number of lines shown in the diagram indicate the weight parameters in the model that are adjusted during training.

在上面的网络中,我们有4个输入节点,4个隐藏层和1个输出。 图中显示的线数表示训练期间调整的模型中的权重参数。

Recurrent Networks are similar to Feed Forward Network with the only difference that it has to remember the data at each step. The history of each step has to be saved.

递归网络类似于前馈网络,唯一的区别是它必须在每个步骤中记住数据。 必须保存每个步骤的历史记录。

Here is a simple Layout of Recurrent Network −

这是循环网络的简单布局-

Recurrent Networks

PyBrain-使用网络 (PyBrain - Working With Networks)

A network is composed of modules, and they are connected using connections. In this chapter, we will learn to −

网络由模块组成,并使用连接进行连接。 在本章中,我们将学习-

  • Create Network

    建立网络
  • Analyze Network

    分析网络

建立网络 (Creating Network)

We are going to use python interpreter to execute our code. To create a network in pybrain, we have to use buildNetwork api as shown below −

我们将使用python解释器执行我们的代码。 要在pybrain中创建网络,我们必须使用buildNetwork api,如下所示-


C:\pybrain\pybrain>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> from pybrain.tools.shortcuts import buildNetwork
>>> network = buildNetwork(2, 3, 1)
>>>

We have created a network using buildNetwork() and the params are 2, 3, 1 which means the network is made up of 2 inputs, 3 hidden and one single output.

我们使用buildNetwork()创建了一个网络,参数为2、3、1,这意味着该网络由2个输入,3个隐藏和1个单个输出组成。

Below are the details of the network, i.e., Modules and Connections −

以下是网络的详细信息,即模块和连接-


C:\pybrain\pybrain>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pybrain.tools.shortcuts import buildNetwork
>>> network = buildNetwork(2,3,1)
>>> print(network)
FeedForwardNetwork-8
   Modules:
   [<BiasUnit 'bias'>, <Li
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值