无法使用 Accord.Net 框架实现基本决策树



我正在尝试学习如何在C#中实现决策树。我真的是这个主题的新手,我正在使用Accord网站上给出的示例来学习。我的代码都从网站上复制了,但是Visual Studio一直告诉我:Visual Studio无法开始调试,因为丢失了调试目标。我的代码是:

    using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Accord;
using Accord.MachineLearning.DecisionTrees;
using Accord.MachineLearning.DecisionTrees.Learning;
using Accord.Math;
using Accord.Statistics.Filters;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            DataTable data = new DataTable("Mitchell's Tennis Example");
            data.Columns.Add("Day", "Outlook", "Temperature", "Humidity", "Wind", "PlayTennis");
            data.Rows.Add("D1", "Sunny", "Hot", "High", "Weak", "No");
            data.Rows.Add("D2", "Sunny", "Hot", "High", "Strong", "No");
            data.Rows.Add("D3", "Overcast", "Hot", "High", "Weak", "Yes");
            data.Rows.Add("D4", "Rain", "Mild", "High", "Weak", "Yes");
            data.Rows.Add("D5", "Rain", "Cool", "Normal", "Weak", "Yes");
            data.Rows.Add("D6", "Rain", "Cool", "Normal", "Strong", "No");
            data.Rows.Add("D7", "Overcast", "Cool", "Normal", "Strong", "Yes");
            data.Rows.Add("D8", "Sunny", "Mild", "High", "Weak", "No");
            data.Rows.Add("D9", "Sunny", "Cool", "Normal", "Weak", "Yes");
            data.Rows.Add("D10", "Rain", "Mild", "Normal", "Weak", "Yes");
            data.Rows.Add("D11", "Sunny", "Mild", "Normal", "Strong", "Yes");
            data.Rows.Add("D12", "Overcast", "Mild", "High", "Strong", "Yes");
            data.Rows.Add("D13", "Overcast", "Hot", "Normal", "Weak", "Yes");
            data.Rows.Add("D14", "Rain", "Mild", "High", "Strong", "No");
            // Create a new codification codebook to 
            // convert strings into integer symbols
            Codification codebook = new Codification(data, "Outlook", "Temperature", "Humidity", "Wind", "PlayTennis");

            // Translate our training data into integer symbols using our codebook:
            DataTable symbols = codebook.Apply(data);
            int[][] inputs = symbols.ToArray<int>("Outlook", "Temperature", "Humidity", "Wind");
            int[] outputs = symbols.ToArray<int>("PlayTennis");
            // Gather information about decision variables
            DecisionVariable[] attributes =
{
            new DecisionVariable("Outlook",     3), // 3 possible values (Sunny, overcast, rain)
            new DecisionVariable("Temperature", 3), // 3 possible values (Hot, mild, cool)  
            new DecisionVariable("Humidity",    2), // 2 possible values (High, normal)    
            new DecisionVariable("Wind",        2)  // 2 possible values (Weak, strong) 
    };
            int classCount = 2; // 2 possible output values for playing tennis: yes or no
            //Create the decision tree using the attributes and classes
            DecisionTree tree = new DecisionTree(attributes, classCount);
            // Create a new instance of the ID3 algorithm
            ID3Learning id3learning = new ID3Learning(tree);
            // Learn the training instances!
            id3learning.Run(inputs, outputs);
            string answer = codebook.Translate("PlayTennis", tree.Compute(codebook.Translate("Sunny", "Hot", "High", "Strong")));
            Console.WriteLine("Calculate for: Sunny, Hot, High, Strong");
            Console.WriteLine("Answer: " + answer);
        }
    }
}

P.S。我正在使用Visual Studio社区2017。

来自这个问题

  1. 确保项目的输出路径正确(项目> properties>构建>输出路径(
  2. 进入菜单以构建> Configuration Manager,并检查您的主/条目项目是否已检查。如果没有,请检查。

这似乎可以解决大多数用户的问题。

最新更新