예제 #1
0
        /// <summary>
        ///   Creates a new <see cref="KNearestNeighbors"/> algorithm from an existing
        ///   <see cref="KDTree{T}"/>. The tree must have been created using the input
        ///   points and the point's class labels as the associated node information.
        /// </summary>
        ///
        /// <param name="tree">The <see cref="KDTree{T}"/> containing the input points and their integer labels.</param>
        /// <param name="k">The number of nearest neighbors to be used in the decision.</param>
        /// <param name="classes">The number of classes in the classification problem.</param>
        /// <param name="inputs">The input data points.</param>
        /// <param name="outputs">The associated labels for the input points.</param>
        ///
        /// <returns>A <see cref="KNearestNeighbors"/> algorithm initialized from the tree.</returns>
        ///
        public static KNearestNeighbors FromTree(KDTree <int> tree, int k, int classes, double[][] inputs, int[] outputs)
        {
            var knn = new KNearestNeighbors();

            knn.K               = k;
            knn.Inputs          = inputs;
            knn.Outputs         = outputs;
            knn.NumberOfInputs  = inputs.Columns();
            knn.NumberOfOutputs = outputs.DistinctCount();
            knn.NumberOfClasses = knn.NumberOfOutputs;
            knn.tree            = tree;

            return(knn);
        }
예제 #2
0
        //Predict match for paraticipate of each user
        public Hashtable Predict(int userID, SportEvent sevent)
        {
            Hashtable answersTable = new Hashtable();

            //Building vector from data
            double[][] test = new double[][]
            {
                new double[] { sevent.CategoryID, sevent.PlaceID }
            };
            foreach (DictionaryEntry s in usersTraining)
            {
                //foreach user except the creator of the user
                if (!s.Key.Equals(userID))
                {
                    //Checking for a match
                    Accord.MachineLearning.KNearestNeighbors model = s.Value as Accord.MachineLearning.KNearestNeighbors;
                    int[] answers    = model.Decide(test);
                    bool  answerBool = answers[0] != 0;
                    answersTable.Add(s.Key, answerBool);
                    Debug.WriteLine("User" + s.Key + ". This event is suitable for him: " + answers[0]);
                }
            }
            return(answersTable);
        }
예제 #3
0
        /// <summary>
        ///   Creates a new <see cref="KNearestNeighbors"/> algorithm from an existing
        ///   <see cref="KDTree{T}"/>. The tree must have been created using the input
        ///   points and the point's class labels as the associated node information.
        /// </summary>
        ///
        /// <param name="tree">The <see cref="KDTree{T}"/> containing the input points and their integer labels.</param>
        /// <param name="k">The number of nearest neighbors to be used in the decision.</param>
        /// <param name="classes">The number of classes in the classification problem.</param>
        /// <param name="inputs">The input data points.</param>
        /// <param name="outputs">The associated labels for the input points.</param>
        ///
        /// <returns>A <see cref="KNearestNeighbors"/> algorithm initialized from the tree.</returns>
        ///
        public static KNearestNeighbors FromTree(KDTree <int> tree, int k, int classes, double[][] inputs, int[] outputs)
        {
            var knn = new KNearestNeighbors(tree, k, classes, inputs, outputs, tree.Distance);

            return(knn);
        }