C# 中的机器学习库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1624060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
machine learning libraries in C#
提问by Dervin Thunk
采纳答案by Simon P Stevens
Check out this awesome liston GitHub. Of the frameworks listed, Accord.NET is open-source and the most popular with over 2,000 stars.
在 GitHub 上查看这个很棒的列表。在列出的框架中,Accord.NET 是开源的并且最受欢迎,拥有超过 2,000 颗星。
Also, check out the official machine learning library for .NET provided by Microsoft: https://github.com/dotnet/machinelearning
另外,请查看 Microsoft 提供的用于 .NET 的官方机器学习库:https: //github.com/dotnet/machinelearning
OLD
老的
There's a neural network library called AForge.neton the codeproject. (Code hosted at Google code) (Also checkout the AForge homepage- According to the homepage, the new version now supports genetic algorithms and machine learning as well. It looks like it's progressed a lot since I last played with it)
codeproject上有一个叫做AForge.net的神经网络库。(代码托管在谷歌代码)(另请查看 AForge 主页- 根据主页,新版本现在也支持遗传算法和机器学习。看起来自从我上次玩它以来进步了很多)
I don't know it's it's anything like WEKA as I've never used that.
我不知道它是否像 WEKA,因为我从未使用过它。
(there's also an article on it's usage)
(还有一篇关于它用法的文章)
回答by Shane
You can also use Weka with C#. The best solution is to use IKVM, as in this tutorial, although you can also use bridging software.
您还可以将 Weka 与 C# 一起使用。最好的解决方案是使用IKVM,如本教程中所示,尽管您也可以使用桥接软件。
回答by Seth Juarez
I have created an ML libraryin C# that is designed to work with common POCO objects.
我在 C# 中创建了一个ML 库,旨在处理常见的 POCO 对象。
回答by Gregor Slavec
Weka can be used from C# very easily as Shane stated, using IKVM and some 'glue code'. Folow the tutorial on weka pageto create the '.Net version' of weka, then you can try to run the following tests:
正如 Shane 所说,Weka 可以很容易地从 C# 中使用,使用 IKVM 和一些“胶水代码”。按照weka页面上的教程创建weka的'.Net版',然后您可以尝试运行以下测试:
[Fact]
public void BuildAndClassify()
{
var classifier = BuildClassifier();
AssertCanClassify(classifier);
}
[Fact]
public void DeserializeAndClassify()
{
BuildClassifier().Serialize("test.weka");
var classifier = Classifier.Deserialize<LinearRegression>("test.weka");
AssertCanClassify(classifier);
}
private static void AssertCanClassify(LinearRegression classifier)
{
var result = classifier.Classify(-402, -1);
Assert.InRange(result, 255.8d, 255.9d);
}
private static LinearRegression BuildClassifier()
{
var trainingSet = new TrainingSet("attribute1", "attribute2", "class")
.AddExample(-173, 3, -31)
.AddExample(-901, 1, 807)
.AddExample(-901, 1, 807)
.AddExample(-94, -2, -86);
return Classifier.Build<LinearRegression>(trainingSet);
}
First test shows, how you build a classifier and classify a new Example with it, the second one shows, how you can use a persisted classifier from a file to classify an example. If you need too support discrete attributes, some modification will be necessery. The code above uses 2 helper classes:
第一个测试显示了如何构建分类器并使用它对新示例进行分类,第二个测试显示如何使用文件中的持久分类器对示例进行分类。如果您太需要支持离散属性,则需要进行一些修改。上面的代码使用了 2 个辅助类:
public class TrainingSet
{
private readonly List<string> _attributes = new List<string>();
private readonly List<List<object>> _examples = new List<List<object>>();
public TrainingSet(params string[] attributes)
{
_attributes.AddRange(attributes);
}
public int AttributesCount
{
get { return _attributes.Count; }
}
public int ExamplesCount
{
get { return _examples.Count; }
}
public TrainingSet AddExample(params object[] example)
{
if (example.Length != _attributes.Count)
{
throw new InvalidOperationException(
String.Format("Invalid number of elements in example. Should be {0}, was {1}.", _attributes.Count,
_examples.Count));
}
_examples.Add(new List<object>(example));
return this;
}
public static implicit operator Instances(TrainingSet trainingSet)
{
var attributes = trainingSet._attributes.Select(x => new Attribute(x)).ToArray();
var featureVector = new FastVector(trainingSet.AttributesCount);
foreach (var attribute in attributes)
{
featureVector.addElement(attribute);
}
var instances = new Instances("Rel", featureVector, trainingSet.ExamplesCount);
instances.setClassIndex(trainingSet.AttributesCount - 1);
foreach (var example in trainingSet._examples)
{
var instance = new Instance(trainingSet.AttributesCount);
for (var i = 0; i < example.Count; i++)
{
instance.setValue(attributes[i], Convert.ToDouble(example[i]));
}
instances.add(instance);
}
return instances;
}
}
public static class Classifier
{
public static TClassifier Build<TClassifier>(TrainingSet trainingSet)
where TClassifier : weka.classifiers.Classifier, new()
{
var classifier = new TClassifier();
classifier.buildClassifier(trainingSet);
return classifier;
}
public static TClassifier Deserialize<TClassifier>(string filename)
{
return (TClassifier)SerializationHelper.read(filename);
}
public static void Serialize(this weka.classifiers.Classifier classifier, string filename)
{
SerializationHelper.write(filename, classifier);
}
public static double Classify(this weka.classifiers.Classifier classifier, params object[] example)
{
// instance lenght + 1, because class variable is not included in example
var instance = new Instance(example.Length + 1);
for (int i = 0; i < example.Length; i++)
{
instance.setValue(i, Convert.ToDouble(example[i]));
}
return classifier.classifyInstance(instance);
}
}
回答by vanni.torelli
There's also a project called Encog that has C# code. It's maintained by Jeff Heaton, the author of an "Introduction to Neural Network" book I bought a while ago. The codebase Git is here: https://github.com/encog/encog-dotnet-core
还有一个名为 Encog 的项目,其中包含 C# 代码。它由 Jeff Heaton 维护,他是我不久前购买的“神经网络简介”一书的作者。代码库 Git 在这里:https: //github.com/encog/encog-dotnet-core
回答by Ole Lynge
I'm searching for machine learning libraries for .NET as well and found Infer.NET from Microsoft Research on nuget.org/machine-learning:
我也在为 .NET 搜索机器学习库,并在 nuget.org/machine-learning 上找到了来自 Microsoft Research 的Infer.NET: