[英]Classification with Accord.net library throw IndexOutOfRangeException
I am new to machine learning. 我是机器学习的新手。 I am using Accord.NET 我正在使用Accord.NET
I have a simple problem of classification, I have some period of time, and each period has it is own type according to the start time of the period and the end time of the period (this is a simplified description of the description) 我有一个简单的分类问题,我有一段时间,每个时期都有自己的类型,具体取决于时期的开始时间和时期的结束时间(这是描述的简化描述)
I tried to write this code to learn the machine but it is always throw 我试图编写这段代码来学习机器,但是总是抛出
System.IndexOutOfRangeException : Index was outside the bounds of the array. System.IndexOutOfRangeException:索引超出数组的范围。
List<List<int>> trainingList = ConvertDuruslarToIntegerList();
int[][] inputs = GetInputs(trainingList);
int[] outputs = GetOutpus(trainingList);
int[] distinct = outputs.Distinct().ToArray();
Dictionary<int, int> dic = new Dictionary<int, int>();
for (int i = 0; i < distinct.Length; i++)
dic.Add(distinct[i], i + 1);
List<int> preparedOutput = new List<int>();
for (int i = 0; i < outputs.Length; i++)
preparedOutput.Add(dic[outputs[i]]);
int classesCount = preparedOutput.Distinct().Count();
var allthings = inputs.Aggregate((x, y) => x.Concat(y).ToArray()).Concat(preparedOutput);
var minAllthings = allthings.Min();
var maxAllthings = allthings.Max();
var symbolsCount = maxAllthings - minAllthings + 1;
var function = new MarkovDiscreteFunction(states: classesCount, symbols: symbolsCount, outputClasses: classesCount);
var classifier = new HiddenConditionalRandomField<int>(function);
// Create a learning algorithm
var teacher = new HiddenResilientGradientLearning<int>(classifier)
{
MaxIterations = 10
};
// Run the algorithm and learn the models
teacher.Learn(inputs, preparedOutput.ToArray());
the exception is thrown in the teacher.Learn
method 例外情况是在teacher.Learn
方法中引发的
Accord expects classes to be zero-based. 雅阁期望类从零开始。 You can successfully learn if you change the following line: 您可以成功学习如果更改以下行:
dic.Add(distinct[i], i);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.