感知器的决策边界太小 [英] decision boundary of perceptron too small

查看:51
本文介绍了感知器的决策边界太小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制感知器算法的决策边界,但对一些事情感到非常困惑.我的输入实例采用 [(x1,x2),target_Value] 形式,基本上是一个二维输入实例和一个 2 类 target_value [1 或 0].

I am trying to plot the decision boundary of a perceptron algorithm and am really confused about a few things. My input instances are in the form [(x1,x2),target_Value], basically a 2-d input instance and a 2 class target_value [1 or 0].

因此,我的权重向量采用以下形式:[w1,w2] 现在我必须加入一个额外的偏置参数 w0,因此我的权重向量变成了 3x1 向量?是1x3向量吗?我认为它应该是 1x3,因为向量只有 1 行和 n 列.

My weight vector hence is in the form: [w1,w2] Now I have to incorporate an additional bias parameter w0 and hence my weight vector becomes a 3x1 vector? is it 1x3 vector? I think it should be 1x3 since a vector has only 1 row and n columns.

现在让我们说我将[w0,w1,w2]实例化为随机值,该如何绘制决策边界?含义w0在这里表示什么?w0/norm(w)是决策区域距原点的距离吗?如果是这样,我该如何捕获它并使用matplotlib.pyplot或其等效的matlab在python中对其进行绘制?对于这个问题,我什至会提供一点帮助.

Now let's say I instantiate [w0,w1,w2] to random values, how would I plot the decision boundary for this? Meaning what does w0 signify here? Is w0/norm(w) the distance of the decision region from the origin? If so how do I capture this and plot it in python using matplotlib.pyplot or its matlab equivalent? I would really appreciate even a little help regarding this matter.

from pylab import norm
import matplotlib.pyplot as plt

n = norm(weight_vector) #this is of the form [w0,w1,w2], w0 is bias parameter
ww = weight_vector/n   #unit vector in the direction of weight_vector
ww1 = [ww[1],-ww[0]]
ww2 = [-ww[1],ww[0]]
plot([ww1[0], ww2[0]],[ww1[1], ww2[1]],'--k')

在这里,我想合并w0参数以指示权重矢量与原点的距离,因为那是w0/norm(w)所指示的?

Here I want to incorporate the w0 parameter to indicate the distance of the displacement of the weight vector from the origin since that's what w0/norm(w) indicates?

当我绘制下面评论中提到的向量时,我得到一个长度非常小的向量,我怎么可能在两个方向上扩展这个决策边界?

When I plot the vector as mentioned in the comments below I get a vector of really small length, how would it be possible for me to extend this decision boundary in both directions?

图中位置[0,0]附近的小虚线是我的决策区域,如何让它在两个方向都变长?如果我尝试将其每个分量相乘,则图形比例会发生变化,我正在使用matplotlib.pyplot.plot()函数来实现这一目标.

The small dashed line near location [0,0] in the figure is my decision region, how can I make it longer in both directions? If I try to multiply each of its components, the figure scale changes, I am using matplotlib.pyplot.plot() function to achieve this.

推荐答案

首先,您不应该在输入向量上加上偏差.您只需要对所有输入向量减去或增加偏差即可.对于绘图,您可能想尝试绘制通过两个权重点的线性函数.

First of all, you shouldn't add the bias to the input vectors. You only need to subtract or add the bias to all of your input vectors. For plotting, you might want to try plot the linear function that passes the two weight points.

这篇关于感知器的决策边界太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆