- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试按照教程 http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_ml/py_knn/py_knn_opencv/py_knn_opencv.html 进行操作并将 KNearest
替换为 cv2.m1.KNearest_create()
但我收到 TypeError: only length-1 arrays can be conversion to Python scalars
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('digits.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Now we split the image to 5000 cells, each 20x20 size
cells = [np.hsplit(row,100) for row in np.vsplit(gray,50)]
# Make it into a Numpy array. It size will be (50,100,20,20)
x = np.array(cells)
# Now we prepare train_data and test_data.
train = x[:,:50].reshape(-1,400).astype(np.float32) # Size = (2500,400)
test = x[:,50:100].reshape(-1,400).astype(np.float32) # Size = (2500,400)
# Create labels for train and test data
k = np.arange(10)
train_labels = np.repeat(k,250)[:,np.newaxis]
test_labels = train_labels.copy()
# Initiate kNN, train the data, then test it with test data for k=1
cv2.m1.KNearest_create()
knn.train(train,train_labels)
ret,result,neighbours,dist = knn.find_nearest(test,k=5)
# Now we check the accuracy of classification
# For that, compare the result with test_labels and check which are wrong
matches = result==test_labels
correct = np.count_nonzero(matches)
accuracy = correct*100.0/result.size
print accuracy
(我正在使用树莓派并按照本教程安装 open cv http://www.pyimagesearch.com/2015/10/26/how-to-install-opencv-3-on-raspbian-jessie/ 随后我 pip 安装了 matplotlib)
最佳答案
参数cv2.ml.ROW_SAMPLE丢失,将knn.find_nearest(test,k=5)修改为下面的代码。这是openCv3中的新功能,请引用openCv官网http://docs.opencv.org/3.0.0/dd/de1/classcv_1_1ml_1_1KNearest.html
` knn.train(train, cv2.ml.ROW_SAMPLE, train_labels)
ret, result, neighbours, dist = knn.findNearest(test, k=5)`
关于python - opencv knn 类型错误 : only length-1 arrays can be converted to Python scalars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37034596/
library(ISLR) standardized.X=scale(Caravan [,-86]) test =1:1000 train.X=standardized.X[-test ,] test
这可能是一个愚蠢的问题,但我只是想知道在 scikit.ml 中实现的 ML-KNN 与 scikit-learn 的 KNeighborsClassifier 之间的区别是什么。根据sklearn'
我担心我的预测与测试的准确性,这完全有意义。 X_train , X_test, y_train ,y_test =train_test_split(iris_dataset['data'], iri
我已经开始在 python tensorflow 库上使用 K-Nearest-Neighbors 方法开发一个机器学习项目。我没有使用tensorflow工具的经验,所以我在github上找到了一些
大侠幸会,在下全网同名「算法金」 0 基础转 AI 上岸,多个算法赛 Top 「日更万日,让更多人享受智能乐趣」 KNN算法的工作原理简单直观,易于理解和实现,这使得它在各种应用场景
我试图在 R 中使用 knn(使用了几个包( knnflex , class ))来预测基于 8 个变量的违约概率。数据集大约有 100k 行 8 列,但我的机器似乎很难处理 10k 行的样本。在数据
我有一个 60.000 obs/40 变量数据集,我在其中使用了 Clara,主要是由于内存限制。 library(cluster) library(dplyr) mutate(kddne
我尝试运行这条线: knn(mydades.training[,-7],mydades.test[,-7],mydades.training[,7],k=5) 但我总是收到这个错误: Error in
我正在尝试使用 python 实现 k-近邻算法。我最终得到了以下代码。但是,我正在努力寻找最近邻居项目的索引。以下函数将返回距离矩阵。但是,我需要在features_train(算法的输入矩阵)中获
我正在使用Kobe Bryant Dataset 。我希望用 KnnRegressor 预测 shot_made_flag。 我使用game_date来提取year和month特征: # covert
在 kNN classifier 的文档中,有一个方法kneighbors ,返回 k 个最近邻居。我感兴趣的是如何优雅地返回此类分类器中的 k 个最远邻居? 最佳答案 不,没有这样的能力。 您需要记
我想优化 KNN。关于SVM、RF和XGboost的内容有很多;但对于 KNN 来说很少。 据我所知,邻居的数量是一个需要调整的参数。 但是还有哪些参数需要测试呢?有什么好的文章吗? 谢谢 最佳答案
我正在尝试使用具有两列的数据集进行词袋问题 - 摘要和解决方案。我正在使用 KNN。训练数据集有 91 列,测试数据集有 15 列。 为了生成向量,我使用以下代码。 vectorizer = Coun
我了解 k 最近邻 (KNN) 的工作原理,但我不熟悉“软投票”一词。与 KNN 相关的软投票是什么?它与标准 KNN 投票相比如何工作? 比较两种投票方案的简单示例会很有用,并且指向 Matlab
我正在尝试将 KNN 应用到 tips 数据集 并将对象映射如下: f.Male=df.Gender.map({'Female':0,'Male':1}) df.Smokes = df.Smoker.
在下面的代码(最后一行)中,根据文档使用了 X_test 和 y_test: Returns the mean accuracy on the given test data and label 问题
我有约 65 个特征、450k 个观察值和不平衡的分类响应变量 Y(约 5% 真实,2 个状态)的 df。这已通过 train_test_split 分为 {Xtrain, ytrain} (10%)
为什么在 KNN 中需要规范化?我知道这个过程标准化了所有特征对结果的影响,但是在标准化之前到特定点 V 的“K”最近点将与到该特定点的“K”最近点完全相同归一化后的 V。那么归一化对欧氏距离有何影响
我目前正在为我的人工智能考试做一个机器学习项目。目标是使用 WEKA 正确选择两种分类算法进行比较,请记住,这两种算法必须有足够的不同才能进行比较。此外,算法必须同时处理标称数据和数字数据(我想这是进
进行数据挖掘时,什么时候应该选择其中一种算法而不是另一种?有具体原因吗?另外,其中哪一个是最有效的? 我将给出一个表格作为示例。 最佳答案 一种选择方法是尝试所有这些并选择最好的。 如果我要尝试构建数
我是一名优秀的程序员,十分优秀!