Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string        pathToData    = "DATA";
            string        pathToResults = "wynik.txt";
            bool          runOneTime    = true;
            DirectoryInfo di            = new DirectoryInfo(pathToData + "\\letterB");

            using (var tw = new StreamWriter(pathToResults, true))
            {
                foreach (var csv in di.GetFiles("*.csv"))
                {
                    IDataProvider       dataProvider = new MockDataProvider();
                    Classifier <string> classifier   = new Classifier <string>();

                    var sampleData = dataProvider.GetTrainingData(pathToData, csv.Name, ExcludeType.b) as List <InformationModel>;

                    classifier.Teach(sampleData);

                    List <List <string> > values = new List <List <string> >();

                    values.AddRange(File.ReadAllLines(csv.FullName)
                                    .Skip(1)
                                    .Select(FromCsv)
                                    .ToList());

                    Dictionary <string, int> counter = new Dictionary <string, int>()
                    {
                        { "m", 0 }, { "f", 0 }, { "b", 0 }
                    };

                    foreach (var list in values)
                    {
                        IDictionary <string, double> tempDict = classifier.Classify(list);
                        double min = 0;
                        string cat = "";

                        foreach (var item in tempDict)
                        {
                            if (min == 0 || min > item.Value)
                            {
                                min = item.Value;
                                cat = item.Key;
                            }
                        }

                        counter[cat]++;
                    }

                    foreach (var item in counter)
                    {
                        tw.Write("{1}; ", item.Key, item.Value);
                    }

                    tw.WriteLine();

                    if (runOneTime)
                    {
                        break;
                    }
                }
            }
        }
        public List <TestDataSet> Main()
        {
            IDataProvider                        dataProvider = new MockDataProvider();
            List <GetTestData_Result>            tempData     = new List <GetTestData_Result>();
            List <TestDataSet>                   testData     = new List <TestDataSet>();
            List <IDictionary <string, double> > dictionaries = new List <IDictionary <string, double> >();

            using (FRDBEntities db = new FRDBEntities())
            {
                tempData = db.GetTestData().ToList <GetTestData_Result>();
            }

            Classifier <string> classifier = new Classifier <string>();
            var sampleData = dataProvider.GetTrainingData() as List <InformationModel <string> >;

            classifier.Teach(sampleData);
            int temp = tempData.FirstOrDefault <GetTestData_Result>().UserID;
            List <GetTestData_Result> list = new List <GetTestData_Result>();
            int lenth = tempData.Count;
            int count = 1;

            foreach (var item in tempData)
            {
                if (temp == item.UserID)
                {
                    IDictionary <string, double> dict = classifier.Classify(new List <string>()
                    {
                        item.skill, BinData(item.skill, item.skillrate), item.interest, BinData(item.interest, item.interestrate)
                    });
                    dictionaries.Add(dict);
                    if (count == lenth)
                    {
                        foreach (var d in add(dictionaries))
                        {
                            testData.Add(new TestDataSet {
                                uid = temp, major = d.Key, probabilty = d.Value
                            });
                        }
                    }
                }
                else
                {
                    foreach (var d in add(dictionaries))
                    {
                        testData.Add(new TestDataSet {
                            uid = temp, major = d.Key, probabilty = d.Value
                        });
                    }

                    temp = item.UserID;
                    dictionaries.Clear();
                    IDictionary <string, double> dict = classifier.Classify(new List <string>()
                    {
                        item.skill, BinData(item.skill, item.skillrate), item.interest, BinData(item.interest, item.interestrate)
                    });
                    dictionaries.Add(dict);
                }
                count++;
            }

            return(testData);
        }