Пример #1
0
        /// <summary>
        /// Predicts special coverage of the article using built model
        /// </summary>
        /// <param name="article">Article classified by the method</param>
        /// <returns>Special coverage predicted by the model</returns>
        public int Classify(Article article)
        {
            var newX       = ProblemBuilder.CreateNode(ArticleFeatures(article), vocabulary.ToList()); //create node
            var predictedY = model.Predict(newX);                                                      //get special coverage

            return((int)predictedY);
        }
Пример #2
0
        /// <summary>
        /// Constructor that creates object with given training set and testing set
        /// </summary>
        /// <param name="trainingSet">Training set loaded from a file</param>
        /// <param name="testingSet">Testing set loaded from a file</param>
        public SVMClassifier(TrainingSet trainingSet, TestingSet testingSet)
        {
            this.trainingSet = trainingSet;
            vocabulary       = new HashSet <string>();
            x = new List <string>();
            y = new List <double>();

            foreach (Article article in trainingSet.articles.Values) //load data from the training set
            {
                string features = ArticleFeatures(article);
                //add features and special coverages to lists
                AddFeaturesToVocabulary(features);
                x.Add(features);
                y.Add(article.specialCoverage[0]);
            }

            foreach (Article article in testingSet.articles.Values) //load articles with given specialCoverage from the testing set
            {
                if (article.specialCoverage != null)
                {
                    string features = ArticleFeatures(article);
                    //add features and special coverages to lists
                    AddFeaturesToVocabulary(features);
                    x.Add(features);
                    y.Add(article.specialCoverage[0]);
                }
            }

            //create new problem
            ProblemBuilder problemBuilder = new ProblemBuilder();
            var            problem        = problemBuilder.CreateProblem(x, y.ToArray(), vocabulary.ToList());

            //create new model using linear kernel
            const int C = 1; //C parameter for C_SVC

            model = new C_SVC(problem, KernelHelper.LinearKernel(), C);
        }