コード例 #1
0
ファイル: Program.cs プロジェクト: phananhtruc98/C4.5
        /// <summary>
        /// GetMaxGainRatio
        /// </summary>
        /// <param name="value_decision_list"></param>
        /// <returns></returns>
        static IntDouble GetMaxGainRatioInContinuous(string[] S, int index_collumn, double entropy_main)
        {
            List <int>       values   = new List <int>();
            List <IntString> new_data = new List <IntString>();

            for (int i = 0; i <= S.Length - 1; i++)
            {
                string[] words = S[i].Split(',');
                values.Add(int.Parse(words[index_collumn]));
                new_data.Add(new IntString(int.Parse(words[index_collumn]), words.Last()));
            }
            values = values.Distinct().OrderBy(x => x).ToList();
            List <IntDouble> gain_ratio_each_value = new List <IntDouble>();

            foreach (int value in values.Distinct().ToList())
            {
                double gain_ratio = GetGainRatio(entropy_main, new_data, value);
                gain_ratio_each_value.Add(new IntDouble(value, gain_ratio));
            }

            double value_max = gain_ratio_each_value.Max(x => x.Value);

            IntDouble rs = gain_ratio_each_value.Where(x => x.Value == value_max).FirstOrDefault();

            return(rs);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: phananhtruc98/C4.5
        static string[] ConvertContinuous(string[] S, List <int> index_collumns, double entropy_main)
        {
            List <string> S_new = new List <string>();

            foreach (int index in index_collumns)
            {
                IntDouble        final    = GetMaxGainRatioInContinuous(S, index, entropy_main);
                List <int>       values   = new List <int>();
                List <IntString> new_data = new List <IntString>();
                S_new = new List <string>();
                for (int i = 0; i <= S.Length - 1; i++)
                {
                    string[] words = S[i].Split(',');
                    if (int.Parse(words[index]) <= final.Key)
                    {
                        words[index] = "<=" + final.Key.ToString();
                    }
                    else
                    {
                        words[index] = ">" + final.Key.ToString();
                    }
                    S_new.Add(String.Join(",", words));
                }
                S = S_new.ToArray();
            }
            return(S_new.ToArray());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: phananhtruc98/C4.5
        private static IntDouble MakeDecision(string[] S, double entropy_main)
        {
            List <IntDouble> listGainRatio = new List <IntDouble>();

            for (int i = 0; i <= S[0].Split(',').Length - 2; i++)
            {
                List <StringString> dataset = new List <StringString>();
                for (int j = 0; j <= S.Length - 1; j++)
                {
                    string[]     words = S[j].Split(',');
                    StringString obj   = new StringString(words[i], S[j].Split(',')[words.Length - 1]);
                    dataset.Add(obj);
                }
                IntDouble gain_ratio = new IntDouble(i, GetGainRatioMain(entropy_main, dataset));
                listGainRatio.Add(gain_ratio);
            }
            double max_gain_ratio = listGainRatio.Max((x => x.Value));

            return(listGainRatio.Where(x => x.Value == max_gain_ratio).FirstOrDefault());
        }