- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 sklearn.svm.SVR
进行“回归任务”,我想使用我的“自定义内核方法”。这是数据集示例和代码:
index density speed label
0 14 58.844020 77.179139
1 29 67.624946 78.367394
2 44 77.679100 79.143744
3 59 79.361877 70.048869
4 74 72.529289 74.499239
.... and so on
from sklearn import svm
import pandas as pd
import numpy as np
density = np.random.randint(0,100, size=(3000, 1))
speed = np.random.randint(20,80, size=(3000, 1)) + np.random.random(size=(3000, 1))
label = np.random.randint(20,80, size=(3000, 1)) + np.random.random(size=(3000, 1))
d = np.hstack((a,b,c))
data = pd.DataFrame(d, columns=['density', 'speed', 'label'])
data.density = data.density.astype(dtype=np.int32)
def my_kernel(X,Y):
return np.dot(X,X.T)
svr = svm.SVR(kernel=my_kernel)
x = data[['density', 'speed']].iloc[:2000]
y = data['label'].iloc[:2000]
x_t = data[['density', 'speed']].iloc[2000:3000]
y_t = data['label'].iloc[2000:3000]
svr.fit(x,y)
y_preds = svr.predict(x_t)
问题发生在最后一行 svm.predict
里面说:
X.shape[1] = 1000 should be equal to 2000, the number of samples at training time
我在网上搜索以找到解决问题的方法,但许多类似的问题(例如 {1}、{ 2 }、{ 3 })都没有得到解答。
实际上,我之前曾将 SVM 方法与 rbf
、sigmoid
等一起使用,代码运行良好,但这是我第一次使用自定义内核和我怀疑一定是这个错误发生的原因。
因此,经过一些研究和阅读文档后,我发现当使用预计算
内核时,SVR.predict()
的矩阵形状必须像[n_samples_test, n_samples_train]
形状。
我想知道如何修改 x_test
以获得预测并且一切正常,没有问题,就像我们不使用自定义内核时一样?
如果可能,请描述“预计算
内核中svm.predict
函数的输入与其他内核不同的原因”。
我真的希望与这个问题相关的悬而未决的问题能够分别得到回答。
最佳答案
问题出在您的内核函数中,它无法完成工作。
作为文档 https://scikit-learn.org/stable/modules/svm.html#using-python-functions-as-kernels说,“你的内核必须将两个形状为 (n_samples_1, n_features)
的矩阵作为参数,(n_samples_2, n_features)
并返回一个形状为 (n_samples_1 , n_samples_2)
。”同一页面上的示例内核满足此条件:
def my_kernel(X, Y):
return np.dot(X, Y.T)
在你的函数中,dot
的第二个参数是 X.T
,因此输出的形状是 (n_samples_1, n_samples_1)
而不是那个预计。
关于python - 我应该如何修改 SVM 方法的测试数据才能使用 `precomputed` 核函数而不会出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55759533/
我使用 4 核 i7 CPU(8 个逻辑核),debian linux 虚拟机也是 debian linux 程序使用 gcc 编译,没有进行特殊优化(默认编译设置) 我循环了该程序 1000 次。当
我有一个实时 linux 桌面应用程序(用 C 语言编写),我们正在移植到 ARM(4 核 Cortex v8-A72 CPU)。在架构上,它结合了高优先级显式 pthread(其中 6 个)和一对
我已经在 Digital Ocean ubuntu 实例上安装了 Solr 6: install_solr_service.sh solr-6.1.0.tgz 并验证 Solr 正在运行。但是,我无法
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 6年前关闭。 Improve this questi
我有一个大约 2000 维的特征向量。都是直方图特征。 我不知道在我的情况下哪个有效:将 SVM 与 RBF 核或卡方核应用? 你能建议我在我的情况下有效的内核吗? 最佳答案 一般来说,卡方和交集内核
我们有一台 12 核 MacPro 来进行一些蒙特卡罗计算。其 Intel Xeon 处理器启用了超线程 (HT),因此实际上应该有 24 个进程并行运行才能充分利用它们。然而,我们的计算在 12x1
所以这段代码: library(plyr) library(doMC) registerDoMC(cores=2) x=1:100 llply(x, some_function, .parallel=
Netty Server 流到 Netty 客户端(点对点,1 对 1): 好的 案例:Server和Client都是12 cores , 1Gbit NIC => 以每秒 300K 200 字节消息
我对以下 C# 代码的线程激活顺序感到困惑。它创建了 10 个线程,随机启动它们,每个线程模拟执行一个耗时的工作 10 次,如果你检查调试输出,线程似乎不是随机选择的,请看下面的输出示例,注意线程 #
这是我考试时提出的问题。我给出了以下答案,我的得分是0分。教授甚至不同意给予任何部分的认可,也没有告诉我我的答案有什么问题。谁能帮我找出我的答案有什么问题吗? 这是我在考试中给出的答案。缺点是:1)
我有一个 Intel Xeon E5-2620,它有 24 个 CPU。我写了一个应用程序,它创建 24 个线程来使用 openssl 解密 AES。当我在 100 万数据解密时将线程数从 1 增加到
我正在开发一个在图层上绘画的应用程序。这是一个示例代码,展示了我的绘画方式。 UIImageView * currentLayer = // getting the right layer... UI
在带有 2Tb DRAM 的 80 核 (160HT) nehalem 架构上运行一些测试后,我遇到了一个小的 HPC 问题: 当每个线程开始请求有关“错误”套接字上的对象的信息时,具有 2 个以上套
由于潜在的性能问题,我刚刚将测试实例从小型“标准”(1 核,1.75GB RAM)实例升级到中型“标准”实例(2 核,3.5GB RAM),这似乎是快速击中。我们确实存在应用程序池回收和必须重新预热某
我知道,为了在 Android 中保持响应式界面,繁重的工作必须在独立线程中完成。我很清楚如何实现这一点(通过使用 AsynTask...等),这不是问题的重点,只是让每个人都知道。 但是我已经在一个
我写了一个简单的多线程 Java 应用程序,主要方法只创建 5k 个线程,每个线程将循环处理一个包含 5M 条记录的列表。 我的机器规范: CPU 内核:12 个内核 内存:13Gb RAM 操作系统
让我们假设我们有固定数量的计算工作,没有阻塞、 sleep 、I/O 等待。工作可以很好地并行化——它由 100M 小而独立的计算任务组成。 什么是 4 核 CPU 的速度更快 - 运行 4 个线程或
我正在使用 WEKA/LibSVM 来训练术语提取系统的分类器。我的数据不是线性可分的,因此我使用 RBF 内核而不是线性内核。 我关注了guide from Hsu et al.并迭代 c 和 ga
谁能告诉我为什么在具有四个 ARMv7 处理器的 Jetson TK1 上调用 Python 的 multiprocessing.cpu_count() 函数会返回 1? >>> import mul
我是一名优秀的程序员,十分优秀!