【发布时间】:2017-01-25 03:14:54
【问题描述】:
我正在尝试使用 Accord 库的 K-最近邻函数,它可以与任何类型一起使用。
我的目标是将它与位图数据一起使用,但即使复制示例代码并粘贴它,我也会收到此错误:
Error 4 The best overloaded method match for 'Accord.MachineLearning.KNearestNeighbors<System.Drawing.Bitmap>.KNearestNeighbors(int, int, System.Drawing.Bitmap[], int[], Accord.Math.Distances.IDistance<System.Drawing.Bitmap>)' has some invalid arguments D:\...\WindowsFormsApplication1\WidgetControl.cs 295 49 Project_Ochare
这真的很奇怪,因为它与示例完全相同。据我所知,参数应该可以工作。 我添加了 Accord 的主要、扩展核心、数学、数学扩展、数学代码、机器学习和统计作为参考。
我尝试搜索,但找不到任何答案..
示例代码与此相同: http://accord-framework.net/docs/html/T_Accord_MachineLearning_KNearestNeighbors_1.htm
怎么了?
这是他们出错的示例代码:
private void __Test()
{
// The k-Nearest Neighbors algorithm can be used with
// any kind of data. In this example, we will see how
// it can be used to compare, for example, Strings.
string[] inputs =
{
"Car", // class 0
"Bar", // class 0
"Jar", // class 0
"Charm", // class 1
"Chair" // class 1
};
int[] outputs =
{
0, 0, 0, // First three are from class 0
1, 1, // And next two are from class 1
};
// Now we will create the K-Nearest Neighbors algorithm. For this
// example, we will be choosing k = 1. This means that, for a given
// instance, only its nearest neighbor will be used to cast a new
// decision.
// In order to compare strings, we will be using Levenshtein's string distance
KNearestNeighbors<string> knn = new KNearestNeighbors<string>(k: 1, classes: 2, inputs: inputs, outputs: outputs, distance: Distance.Levenshtein);
// After the algorithm has been created, we can use it:
int answer = knn.Compute("Chars"); // answer should be 1.
}
这些是我收到的错误消息。我用 KNearest 的 Accord 示例代码创建了一个新的空项目。 它要我将 Distance.Levenshtein 更改为 Distance.Levenshtein(), 然后它告诉我它需要参数,无论我如何编写或添加什么,它都会给出相同的错误。
例如 Distance.Levenshtein("", ""), Distance.Levenshtein(0, 0) Distance.Levenshtein("","")、Distance.Levenshtein(new string1, new string1) 等等……任何我能想到的尝试。
距离。提供了大量的测量功能,它们都会导致相同的错误。
错误信息:
Error 1 The best overloaded method match for 'Accord.MachineLearning.KNearestNeighbors<string>.KNearestNeighbors(int, int, string[], int[], Accord.Math.Distances.IDistance<string>)' has some invalid arguments D:\Dropbox\C#\KNearestTest\KNearestTest\Form1.cs 48 45 KNearestTest
Error 2 Argument 5: cannot convert from 'method group' to 'Accord.Math.Distances.IDistance<string>' D:\Dropbox\C#\KNearestTest\KNearestTest\Form1.cs 49 59 KNearestTest
【问题讨论】:
-
添加代码,但对于错误,我怀疑您正在尝试将位图传递给函数,并且它需要一个项目数组,如果您想操作像素数据,则使用修复数据LockBitmap,将数据读入字节数组,然后对字节数组使用函数。
-
@Gusman 我不确定是否与此有关。即使有他们自己的例子,错误也会弹出:/
-
这个例子的错误只是因为一个错字,而不是
Distance.Levenshtein它应该是Distance.Levenshtein(),因为它是一个方法,而不是一个属性。 -
@Gusman 我试过了,Distance.Levenshtein("","") (因为它要求参数)。同样的红色下划线和消息说有问题:(
-
如果你收到错误添加错误信息,我们没有水晶球来看看VS告诉你什么。
标签: c# .net accord.net