Beispiel #1
0
        public void TrainClassifier(DataTable table)
        {
            dataSet2.Tables.Add(table);

            DataTable GaussianDistribution = dataSet2.Tables.Add("Gaussian");

            GaussianDistribution.Columns.Add(table.Columns[0].ColumnName);

            for (int i = 1; i < table.Columns.Count; i++)
            {
                GaussianDistribution.Columns.Add(table.Columns[i].ColumnName + "Mean");
                GaussianDistribution.Columns.Add(table.Columns[i].ColumnName + "Variance");
            }

            var results = (from myRow in table.AsEnumerable()
                           group myRow by myRow.Field <string>(table.Columns[0].ColumnName) into g
                           select new { Name = g.Key, Count = g.Count() }).ToList();

            for (int j = 0; j < results.Count; j++)
            {
                DataRow row = GaussianDistribution.Rows.Add();
                row[0] = results[j].Name;
                int a = 1;

                for (int i = 1; i < table.Columns.Count; i++)
                {
                    row[a] = VarianceAndMean.Mean(SelectRows(table, i, string.Format("{0} = '{1}'", table.Columns[0].ColumnName, results[j].Name)));

                    row[++a] = VarianceAndMean.Variance(SelectRows(table, i, string.Format("{0} = '{1}'", table.Columns[0].ColumnName, results[j].Name)));
                    a++;
                }
            }
        }
Beispiel #2
0
        //الميثود الخاص بعملية تدريب الخوارزمية على البيانات
        public void TrainClassifier(DataTable table2)
        {
            dataSet.Tables.Add(table2);

            //table
            //استخدام التوزع الغوصي
            DataTable GaussianDistribution = dataSet.Tables.Add("Gaussian");

            GaussianDistribution.Columns.Add(table2.Columns[0].ColumnName);

            //columns
            for (int i = 1; i < table2.Columns.Count; i++)
            {
                GaussianDistribution.Columns.Add(table2.Columns[i].ColumnName + "Mean");
                GaussianDistribution.Columns.Add(table2.Columns[i].ColumnName + "Variance");
            }

            //calc data
            var results = (from myRow in table2.AsEnumerable()
                           group myRow by myRow.Field <string>(table2.Columns[0].ColumnName) into g
                           select new { Name = g.Key, Count = g.Count() }).ToList();

            for (int j = 0; j < results.Count; j++)
            {
                DataRow row = GaussianDistribution.Rows.Add();
                row[0] = results[j].Name;
                int a = 1;

                for (int i = 1; i < table2.Columns.Count; i++)
                {
                    //حساب التبياين
                    row[a] = VarianceAndMean.Mean(SelectRows(table2, i, string.Format("{0} = '{1}'", table2.Columns[0].ColumnName, results[j].Name)));
                    //حساب المتوسط الحسابي
                    row[++a] = VarianceAndMean.Variance(SelectRows(table2, i, string.Format("{0} = '{1}'", table2.Columns[0].ColumnName, results[j].Name)));
                    a++;
                }
            }
        }