- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用本页上的示例 http://scikit-learn.org/stable/auto_examples/svm/plot_iris.html ,我使用一些标准差为 10 的正态分布数据而不是虹膜数据创建了自己的图表。
我的图表是这样的:
请注意 RBF 核图与示例中的核图有很大不同。除了红色和蓝色部分之外,整个区域都被分类为黄色。换句话说,支持向量太多了。我尝试过更改 C 和学位,但没有帮助。我用来生成该图的代码如下所示。
请注意,我需要使用 RBF 内核,因为多项式内核的运行速度比 RBF 内核慢得多。
import numpy as np
import pylab as pl
from sklearn import svm, datasets
FP_SIZE = 50
STD = 10
def gen(fp):
data = []
target = []
fp_count = len(fp)
# generate rssi reading for monitors / fingerprint points
# using scikit-learn data structure
for i in range(0, fp_count):
for j in range(0,FP_SIZE):
target.append(i)
data.append(np.around(np.random.normal(fp[i],STD)))
data = np.array(data)
target = np.array(target)
return data, target
fp = [[-30,-70],[-58,-30],[-60,-60]]
data, target = gen(fp)
# import some data to play with
# iris = datasets.load_iris()
X = data[:, :2] # we only take the first two features. We could
# avoid this ugly slicing by using a two-dim dataset
Y = target
h = .02 # step size in the mesh
# we create an instance of SVM and fit out data. We do not scale our
# data since we want to plot the support vectors
C = 1.0 # SVM regularization parameter
svc = svm.SVC(kernel='linear', C=C).fit(X, Y)
rbf_svc = svm.SVC(kernel='rbf', gamma=0.7, C=C).fit(X, Y)
poly_svc = svm.SVC(kernel='poly', degree=3, C=C).fit(X, Y)
lin_svc = svm.LinearSVC(C=C).fit(X, Y)
# create a mesh to plot in
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
# title for the plots
titles = ['SVC with linear kernel',
'SVC with RBF kernel',
'SVC with polynomial (degree 3) kernel',
'LinearSVC (linear kernel)']
for i, clf in enumerate((svc, rbf_svc, poly_svc, lin_svc)):
# Plot the decision boundary. For that, we will asign a color to each
# point in the mesh [x_min, m_max]x[y_min, y_max].
pl.subplot(2, 2, i + 1)
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
# Put the result into a color plot
Z = Z.reshape(xx.shape)
pl.contourf(xx, yy, Z, cmap=pl.cm.Paired)
pl.axis('off')
# Plot also the training points
pl.scatter(X[:, 0], X[:, 1], c=Y, cmap=pl.cm.Paired)
pl.title(titles[i])
pl.show()
最佳答案
除了您所得到的要点之外,您是否使用了任何其他正确性衡量标准。
通常 SVM 需要使用网格搜索来运行,特别是如果您有 RBF,C 只会负责正则化,如果您的数据一开始就不稀疏,那么这将起不到什么作用。
您需要对 gamma 和 C 运行网格搜索,他们在这里有一个非常好的示例:
http://scikit-learn.org/0.13/auto_examples/grid_search_digits.html#example-grid-search-digits-py
此外,他们的库已经负责交叉验证。
请记住,这些示例对于玩具数据集很有用,当您输入新数据集时,没有理由相信其行为会与示例中的数据集类似。
关于python - 使用 scikit-learn 的 SVM 分类算法(RBF 内核)时出现意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17794313/
如果我在 lrge 训练集上训练 SVM,并且类变量是 True 或 False,那么与训练集中的 False 值数量相比,True 值很少会影响训练模型/结果吗?他们应该平等吗?如果我的训练集的 T
假设我的特征向量是 (x1, x2, ...xn) 谁能给我一个代码来使用 libSVM 训练一类 SVM? 我应该如何使用交叉验证来学习参数。 最佳答案 这可能会帮助你 label=ones(Num
我提前为这个问题的新颖性道歉,但我被卡住了。我正在尝试解决这个问题, 我可以做第 i)-1v) 部分,但我卡在了 v 上。我知道计算余量 y,你可以 y=2/||W|| 而且我知道W是超平面的法线,只
我有以下 R 配置: 操作系统:LinuxR 版本 3.0.1 (2013-05-16)rmr2 版本 2.2.1rhdfs 版本 1.0.6hadoop 版本 1.2.0 如何使用带 rmr2 包的
我想尝试不同的嵌入,例如 Word2Vec、ELMo 和 BERT,但我有点困惑是使用词嵌入还是句子嵌入,以及为什么。我将嵌入用作 SVM 分类器的特征输入。 谢谢。 最佳答案 虽然这两种方法都可以证
几乎所有的例子都是基于数字的。在文本文档中,我有文字而不是数字。 那么你能告诉我如何使用这些算法进行文本文档分类的简单示例吗? 我不需要代码示例,只需要逻辑 伪代码将有很大帮助 最佳答案 常用的方法是
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 3 年前。
我目前正处于语音识别的讨论阶段项目,我使用MFCC特征提取,但是从函数返回的MFCC特征是一个矩阵,例如每个语音文件(wav)的(20,38)特征矩阵。但是我如何将此功能传递给 SVM 分类器。对于
请我喜欢用 SIFT DESCRIPTOR 和 SVM 将一组图像分类为 4 类。现在,使用 SIFT 提取器,我得到了不同大小的关键点,例如 img1 有 100 个关键点,img2 有 55 个关
我有一组图像。我想学习一类支持向量机(OC-SVM)来模拟特定类(正)的分布,因为我没有足够的例子来代表其他类(负)。我对 OC-SVM 的理解是,它试图将数据与源分离,换句话说,它试图学习一个超球体
我正在使用 scikit-learn 使用 SVM 构建一些预测模型。我有一个包含大约 5000 个示例和大约 700 个特征的数据集。我在我的训练集上使用 18x17 网格搜索进行 5 折交叉验证,
这是我考试时提出的问题。我给出了以下答案,我的得分是0分。教授甚至不同意给予任何部分的认可,也没有告诉我我的答案有什么问题。谁能帮我找出我的答案有什么问题吗? 这是我在考试中给出的答案。缺点是:1)
tune.svm() 和 best.svm() 有什么区别。 当我们调整 svm 内核的参数时,我们不希望总是为我们的模型选择最佳值。 请原谅,因为我是 R 和机器学习的新手。 我注意到在调整 svm
我尝试使用 OpenCV2.3 实现基于 SVM 和 HOG 的人员检测系统。但是我卡住了。 我走到这一步:我可以从图像数据库计算 HOG 值,然后我用 LIBSVM 计算 SVM 向量,所以我得到例
Mahout(机器)中围绕 SVM(支持向量机)的任何新发展Learning With Hadoop) 使用 Hadoop?最近 SVM 实现被添加到 Mahout 中。我打算使用 SVM。有人尝试过
我使用 sklearn.svm.SVC 构建支持向量分类器,如下所示。 import numpy as np from sklearn.svm import SVC svc=SVC(proba
我想看看模型是否收敛于我的交叉验证。我如何增加或减少 sklearn.svm.SVC 中的时代? 目前: SVM_Model = SVC(gamma='auto') SVM_Model.fit(X_t
与在 SVM 的相同成本函数中使用 2-范数权重相比,我们如何通过在成本函数中使用 1-范数权重来提高稀疏性。 对于 1-范数:成本函数 - 最小化 ||w||_1 对于 2-范数:成本函数 - 最小
事实上,我不是一个经验丰富的 C++ 程序员,我是一个 C# 程序员,正如你所知道的,它有很大的不同,根据我的机器学习经验,我只使用了 matlab,所以如果我有一些,请原谅概念错误。 我正在尝试在
我正在尝试使用 OpenCV 中的 SVM 加载函数加载 .xml 文件,然后使用预测函数对交通标志进行分类。当到达预测函数的执行时抛出错误: Unhandled exception at 0x000
我是一名优秀的程序员,十分优秀!