public static DecisionTree Create(int[][] x, int[] y, IList <DecisionVariable> attributes)
 {
     if (attributes == null || attributes.Count == 0)
     {
         attributes = DecisionVariable.FromData(x);
     }
     return(Create(y, attributes));
 }
        /// <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);
        }
        /// <summary>
        ///   Learns a model that can map the given inputs to the given outputs.
        /// </summary>
        ///
        /// <param name="x">The model inputs.</param>
        /// <param name="y">The desired outputs associated with each <paramref name="x">inputs</paramref>.</param>
        /// <param name="weights">The weight of importance for each input-output pair (if supported by the learning algorithm).</param>
        ///
        /// <returns>A model that has learned how to produce <paramref name="y"/> given <paramref name="x"/>.</returns>
        ///
        public RandomForest Learn(double[][] x, int[] y, double[] weights = null)
        {
            if (weights != null)
            {
                throw new ArgumentException(Accord.Properties.Resources.NotSupportedWeights, "weights");
            }

            if (forest == null)
            {
                if (this.attributes == null)
                {
                    this.attributes = DecisionVariable.FromData(x);
                }
                this.forest = CreateTree(y);
            }

            run(x, y);
            return(this.forest);
        }
        /// <summary>
        ///   Learns a model that can map the given inputs to the given outputs.
        /// </summary>
        ///
        /// <param name="x">The model inputs.</param>
        /// <param name="y">The desired outputs associated with each <paramref name="x">inputs</paramref>.</param>
        /// <param name="weights">The weight of importance for each input-output pair.</param>
        ///
        /// <returns>A model that has learned how to produce <paramref name="y"/> given <paramref name="x"/>.</returns>
        ///
        public RandomForest Learn(double[][] x, int[] y, double[] weights = null)
        {
            if (forest == null)
            {
                int classes = y.Max() + 1;
                this.forest = new RandomForest(NumberOfTrees, classes);
                if (this.attributes == null)
                {
                    this.attributes = DecisionVariable.FromData(x);
                }
                for (int i = 0; i < forest.Trees.Length; i++)
                {
                    forest.Trees[i] = new DecisionTree(attributes, classes);
                }
            }

            run(x, y);
            return(this.forest);
        }
        /// <summary>
        ///   Learns a model that can map the given inputs to the given outputs.
        /// </summary>
        ///
        /// <param name="x">The model inputs.</param>
        /// <param name="y">The desired outputs associated with each <paramref name="x">inputs</paramref>.</param>
        /// <param name="weights">The weight of importance for each input-output pair (if supported by the learning algorithm).</param>
        ///
        /// <returns>A model that has learned how to produce <paramref name="y"/> given <paramref name="x"/>.</returns>
        ///
        public RandomForest Learn(double[][] x, int[] y, double[] weights = null)
        {
            if (weights != null)
            {
                throw new ArgumentException(Accord.Properties.Resources.NotSupportedWeights, "weights");
            }

            if (forest == null)
            {
                int classes = y.Max() + 1;
                this.forest = new RandomForest(NumberOfTrees, classes);
                if (this.attributes == null)
                {
                    this.attributes = DecisionVariable.FromData(x);
                }
                for (int i = 0; i < forest.Trees.Length; i++)
                {
                    forest.Trees[i] = new DecisionTree(attributes, classes);
                }
            }

            run(x, y);
            return(this.forest);
        }