Inheritance: MulticlassClassifierBase
コード例 #1
1
        /// <summary>
        ///   Learns a new Random Forest with the given data.
        /// </summary>
        /// 
        /// <param name="inputs">The input points.</param>
        /// <param name="output">The class label for each point.</param>
        /// 
        /// <returns>A <see cref="RandomForest"/> object that learned
        ///   how to assign class labels to input points.</returns>
        /// 
        public RandomForest Learn(double[][] inputs, int[] output)
        {
            if (forest == null)
            {
                int classes = output.Max() + 1;
                this.forest = new RandomForest(NumberOfTrees, classes);
                var variables = DecisionVariable.FromData(inputs);
                for (int i = 0; i < forest.Trees.Length; i++)
                    forest.Trees[i] = new DecisionTree(variables, classes);
            }

            run(inputs, output);
            return this.forest;
        }
コード例 #2
0
        /// <summary>
        ///   Learns a new Random Forest with the given data.
        /// </summary>
        ///
        /// <param name="inputs">The input points.</param>
        /// <param name="output">The class label for each point.</param>
        ///
        /// <returns>A <see cref="RandomForest"/> object that learned
        ///   how to assign class labels to input points.</returns>
        ///
        public RandomForest Learn(double[][] inputs, int[] output)
        {
            int classes = output.DistinctCount();

            this.forest = new RandomForest(Trees, classes);
            Run(inputs, output);
            return(this.forest);
        }
コード例 #3
0
        /// <summary>
        ///   Learns a new Random Forest with the given data.
        /// </summary>
        ///
        /// <param name="inputs">The input points.</param>
        /// <param name="output">The class label for each point.</param>
        ///
        /// <returns>A <see cref="RandomForest"/> object that learned
        ///   how to assign class labels to input points.</returns>
        ///
        public RandomForest Learn(double[][] inputs, int[] output)
        {
            if (forest == null)
            {
                int classes = output.Max() + 1;
                this.forest = new RandomForest(NumberOfTrees, classes);
                var variables = DecisionVariable.FromData(inputs);
                for (int i = 0; i < forest.Trees.Length; i++)
                {
                    forest.Trees[i] = new DecisionTree(variables, classes);
                }
            }

            run(inputs, output);
            return(this.forest);
        }
コード例 #4
0
        /// <summary>
        /// <inheritdoc />
        /// </summary>
        public override void Train()
        {
            var inputs  = data.GetSelectedInput(features);
            var outputs = data.GetExpectedClassificationOutput();

            var DecisionVariables = new List <DecisionVariable>();

            for (int i = 0; i < inputs[0].Length; i++)
            {
                DecisionVariables.Add(DecisionVariable.Continuous(i.ToString(), new DoubleRange(0.0, 1.0)));
            }

            var teacher = new RandomForestLearning(DecisionVariables.ToArray())
            {
                NumberOfTrees = 20
            };

            forest = teacher.Learn(inputs, outputs);

            Save();
        }
コード例 #5
0
 protected override void Load()
 {
     forest = Load <Accord.MachineLearning.DecisionTrees.RandomForest>(this.ToString());
 }
コード例 #6
0
 /// <summary>
 ///   Creates a new decision forest learning algorithm.
 /// </summary>
 /// 
 public RandomForestLearning(RandomForest forest)
 {
     this.SampleRatio = 0.632;
     this.NumberOfTrees = forest.Trees.Length;
     this.forest = forest;
 }
コード例 #7
0
 /// <summary>
 ///   Creates a new decision forest learning algorithm.
 /// </summary>
 ///
 public RandomForestLearning(RandomForest forest)
 {
     this.SampleRatio   = 0.632;
     this.NumberOfTrees = forest.Trees.Length;
     this.forest        = forest;
 }