コード例 #1
0
        static void Main(string[] args)
        {
            //Kreiranje neuronske mreze
            NeuralNetwork network = new NeuralNetwork();

            network.Add(new NeuralLayer(4, 3, "sigmoid"));
            network.Add(new NeuralLayer(3, 2, "sigmoid"));
            network.Add(new NeuralLayer(2, 1, "sigmoid"));


            List <double> col_1 = new List <double>();
            List <double> col_2 = new List <double>();
            List <double> col_3 = new List <double>();
            List <double> col_4 = new List <double>();
            List <double> col_5 = new List <double>();

            List <double> col_1Test = new List <double>();
            List <double> col_2Test = new List <double>();
            List <double> col_3Test = new List <double>();
            List <double> col_4Test = new List <double>();
            List <double> col_5Test = new List <double>();


            String[] dataLines = File.ReadAllLines(@"./../../train.csv");

            dataLines = dataLines.Skip(1).ToArray(); //Skipujemo heder u CSV fajlu

            foreach (String linija in dataLines)
            {
                string[] parts = linija.Split(',');
                col_1.Add(double.Parse(parts[(int)Header.col_1], CultureInfo.InvariantCulture));
                col_2.Add(double.Parse(parts[(int)Header.col_2], CultureInfo.InvariantCulture));
                col_3.Add(double.Parse(parts[(int)Header.col_3], CultureInfo.InvariantCulture));
                col_4.Add(double.Parse(parts[(int)Header.col_4], CultureInfo.InvariantCulture));

                String type = (parts[(int)Header.col_5]);
                if (type.Equals("type_1"))
                {
                    col_5.Add(0);
                }
                else if (type.Equals("type_2"))
                {
                    col_5.Add(0.5);
                }
                else
                {
                    col_5.Add(1);
                }
            }

            List <double> col_1Normalizovani = normalizacijaInt(col_1);
            List <double> col_2Normalizovani = normalizacijaInt(col_2);
            List <double> col_3Normalizovani = normalizacijaInt(col_3);
            List <double> col_4Normalizovani = normalizacijaInt(col_4);


            List <List <double> > X = new List <List <double> >();
            List <List <double> > Y = new List <List <double> >();

            for (int i = 0; i < dataLines.Length; i++)
            {
                double[] xTemp = { col_1Normalizovani[i], col_2Normalizovani[i], col_3Normalizovani[i], col_4Normalizovani[i] };
                X.Add(xTemp.ToList());


                double[] yTemp = { col_5[i] };
                Y.Add(yTemp.ToList());
            }

            Console.WriteLine("Training started");
            network.fit(X, Y, 0.1, 0.9, 500);
            Console.WriteLine("Training ended");

            // String[] dataLinesTest = File.ReadAllLines(@"./../../test.csv");
            String[] dataLinesTest = File.ReadAllLines(@"./../../test.csv");
            dataLinesTest = dataLinesTest.Skip(1).ToArray(); //Skipujemo heder u CSV fajlu



            foreach (String linija in dataLinesTest)
            {
                string[] parts = linija.Split(',');

                col_1Test.Add(double.Parse(parts[(int)Header.col_1], CultureInfo.InvariantCulture));
                col_2Test.Add(double.Parse(parts[(int)Header.col_2], CultureInfo.InvariantCulture));
                col_3Test.Add(double.Parse(parts[(int)Header.col_3], CultureInfo.InvariantCulture));
                col_4Test.Add(double.Parse(parts[(int)Header.col_4], CultureInfo.InvariantCulture));
                //  Console.WriteLine(double.Parse(parts[(int)Header.col_4], CultureInfo.InvariantCulture));
                String type = (parts[(int)Header.col_5]);
                if (type.Equals("type_1"))
                {
                    col_5Test.Add(0);
                }
                else if (type.Equals("type_2"))
                {
                    col_5Test.Add(0.5);
                }
                else
                {
                    col_5Test.Add(1);
                }
            }
            List <double> col_1TestNormalizovani = normalizacijaInt(col_1Test);
            List <double> col_2TestNormalizovani = normalizacijaInt(col_2Test);
            List <double> col_3TestNormalizovani = normalizacijaInt(col_3Test);
            List <double> col_4TestNormalizovani = normalizacijaInt(col_4Test);

            /*  foreach (double d in col_4TestNormalizovani)
             * {
             *    Console.WriteLine(d);
             * }*/
            double dobrih = 0;
            double broj   = 0;

            for (int i = 0; i < dataLinesTest.Length; i++)
            {
                double[] x1   = { col_1TestNormalizovani[i], col_2TestNormalizovani[i], col_3TestNormalizovani[i], col_4TestNormalizovani[i] };
                double   type = 0;
                if (network.predict(x1.ToList())[0] < 0.25)
                {
                    type = 0;
                }
                else if (network.predict(x1.ToList())[0] > 0.25 && network.predict(x1.ToList())[0] < 0.75)
                {
                    type = 0.5;
                }
                else
                {
                    type = 1;
                }
                if (col_5Test[i] == type)
                {
                    dobrih++;
                }
                Console.WriteLine("PRediktovana vrednost je " + network.predict(x1.ToList())[0]);
                Console.WriteLine("Stvarna vrednost je " + col_5Test[i]);
                broj++;
            }

            Console.WriteLine("Dobro prediktovanih je  " + dobrih + " od " + broj);
            double procenattacnosti = (dobrih / broj) * 100;

            Console.WriteLine("Tačnost je = " + procenattacnosti + " %");
            Console.ReadLine();



            // Pomocne funckije
            List <double> normalizacijaInt(List <double> listaVrednosti)
            {
                List <double> noramlizovanaLista = new List <double>();

                double dataMax = listaVrednosti.Max();
                double dataMin = listaVrednosti.Min();

                foreach (double vrednost in listaVrednosti)
                {
                    noramlizovanaLista.Add((vrednost - dataMin) / (dataMax - dataMin));
                    // Console.WriteLine("Minimalna vrendost je" + (vrednost - dataMin) / (dataMax - dataMin));
                }
                return(noramlizovanaLista);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            #region Ucitavanje data seta

            List <int> indeksKolonaInputa = new List <int>();

            // ulazi od col_1 do col_5
            indeksKolonaInputa.Add(1);
            indeksKolonaInputa.Add(2);
            indeksKolonaInputa.Add(3);
            indeksKolonaInputa.Add(4);

            List <int> indeksKolonaOutputa = new List <int>();
            // col_5 izlaz
            indeksKolonaOutputa.Add(5);

            FileDAO fileDAO = new FileDAO(indeksKolonaInputa, indeksKolonaOutputa, 0);
            // fileDAO.imaKategorickihAtributa
            // fileDAO.getKategorickeAtribute

            #endregion

            #region Kreiranje neuronske mreze

            NeuralNetwork network = new NeuralNetwork();
            network.Add(new NeuralLayer(indeksKolonaInputa.Count, 2, "sigmoid"));
            //network.Add(new NeuralLayer(3, 2, "sigmoid"));
            network.Add(new NeuralLayer(2, 1, "sigmoid"));

            #endregion

            #region Vektori za inpute

            List <List <double> > X = new List <List <double> >();
            X = fileDAO.X;

            #endregion

            #region Vektori za outpute

            List <List <double> > Y = new List <List <double> >();
            Y = fileDAO.Y;

            #endregion

            #region Fitovanje

            Console.WriteLine("Obuka pocela.");
            network.fit(X, Y, 0.1, 0.9, 3000);
            Console.WriteLine("Kraj obuke.");

            #endregion

            #region Predikcija

            int ukupnoPogodjenih = 0;
            for (int i = 0; i < fileDAO.XTest.Count; ++i)
            {
                List <Double> prediction = network.predict(fileDAO.XTest[i]);

                Console.WriteLine("Pravi rezultat u test podacima je: {0}, Po proracunu i predikciji dobijam {1}", fileDAO.YTest[i][0], prediction[0]);
                // pravi rezultat mi moze biti 0, 0.5 ili 1 pa onda ove sto sam dobio, moram pretvoriti u tip
                // i proveriti da li su odgovarajuceg tipa

                double tip = -1;
                if (prediction[0] <= 0.33)
                {
                    tip = 0;
                }
                else if (prediction[0] > 0.33 && prediction[0] <= 0.66)
                {
                    tip = 0.5;
                }
                else
                {
                    tip = 1;
                }

                if (fileDAO.YTest[i][0] == tip)
                {
                    ++ukupnoPogodjenih;
                }
            }

            Console.Write("Pogodjeno {0} od {1} ", ukupnoPogodjenih, fileDAO.YTest.Count);
            Console.Write("Tacnost {0} %", ukupnoPogodjenih * 100 / fileDAO.YTest.Count);
            Console.ReadLine();

            #endregion
        }
コード例 #3
0
        static void Main(string[] args)
        {
            string[] lines;
            lines = File.ReadAllLines(@"./../../data/heart.csv");
            lines = lines.Skip(1).ToArray();

            List <int>    age               = new List <int>();
            List <int>    pol               = new List <int>();
            List <int>    chestPain         = new List <int>();
            List <int>    RestingBloodP     = new List <int>();
            List <int>    cholesterol       = new List <int>();
            List <int>    fastingBloodSugar = new List <int>();
            List <int>    restingECG        = new List <int>();
            List <int>    thalach           = new List <int>();
            List <int>    excerciseAngina   = new List <int>();
            List <double> oldPeak           = new List <double>();
            List <int>    slope             = new List <int>();
            List <int>    ca       = new List <int>();
            List <int>    thai     = new List <int>();
            List <int>    isTarget = new List <int>();


            Dictionary <String, int> myMap = new Dictionary <String, int>();

            foreach (string line in lines)
            {
                string[] parts = line.Split(',');
                age.Add(int.Parse((parts[(int)HeaderDisese.Age])));
                pol.Add(int.Parse((parts[(int)HeaderDisese.Sex])));
                chestPain.Add(int.Parse((parts[(int)HeaderDisese.Cp])));
                RestingBloodP.Add(int.Parse((parts[(int)HeaderDisese.TrestBps])));
                cholesterol.Add(int.Parse((parts[(int)HeaderDisese.Chol])));
                fastingBloodSugar.Add(int.Parse((parts[(int)HeaderDisese.Fbs])));
                restingECG.Add(int.Parse((parts[(int)HeaderDisese.Restecg])));
                thalach.Add(int.Parse((parts[(int)HeaderDisese.Thalach])));
                excerciseAngina.Add(int.Parse((parts[(int)HeaderDisese.Exang])));
                oldPeak.Add(double.Parse((parts[(int)HeaderDisese.Oldpeak])));
                slope.Add(int.Parse((parts[(int)HeaderDisese.Slope])));
                ca.Add(int.Parse((parts[(int)HeaderDisese.Ca])));
                thai.Add(int.Parse((parts[(int)HeaderDisese.Thal])));
                isTarget.Add(int.Parse((parts[(int)HeaderDisese.Target])));
            }


            NeuralNetwork network = new NeuralNetwork();

            // Two activation functions are supported
            // sigmoid
            // relu
            network.Add(new NeuralLayer(13, 7, "relu"));
            network.Add(new NeuralLayer(7, 4, "relu"));
            network.Add(new NeuralLayer(4, 2, "relu"));
            network.Add(new NeuralLayer(2, 1, "relu"));

            List <List <double> > X = new List <List <double> >();
            List <List <double> > Y = new List <List <double> >();

            // 303 - total
            // 0-30 - test case
            // 30-270 - training data
            // 270-303 - test case
            for (int i = 30; i < 270; i++)
            {
                double[] xTemp = { (double)age[i], (double)pol[i], (double)chestPain[i], (double)RestingBloodP[i], (double)cholesterol[i], (double)fastingBloodSugar[i], (double)restingECG[i], (double)thalach[i], (double)excerciseAngina[i], oldPeak[i], (double)slope[i], (double)ca[i], (double)thai[i] };
                X.Add(xTemp.ToList());


                double[] yTemp = { (double)isTarget[i] };
                Y.Add(yTemp.ToList());
            }

            Console.WriteLine("Training started...");
            network.fit(X, Y, 0.1, 0.9, 500);
            Console.WriteLine("Training finished");

            int hit = 0;

            for (int i = 0; i < 303; i++)
            {
                if (i > 29 && i < 270)
                {
                    continue;
                }
                double[] x1      = { age[i], pol[i], chestPain[i], RestingBloodP[i], cholesterol[i], fastingBloodSugar[i], restingECG[i], thalach[i], excerciseAngina[i], oldPeak[i], slope[i], ca[i], thai[i] };
                int      predict = -1;
                if (network.predict(x1.ToList())[0] < 0.5)
                {
                    predict = 0;
                }
                else
                {
                    predict = 1;
                }
                if (isTarget[i] == predict)
                {
                    hit++;
                }
            }
            Console.WriteLine("Result: " + hit + "/60");
            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            #region Ucitavanje data seta

            List <int> indeksKolonaInputa = new List <int>();

            // popularity
            indeksKolonaInputa.Add(31);

            //male
            indeksKolonaInputa.Add(7);

            // books
            indeksKolonaInputa.Add(16);
            indeksKolonaInputa.Add(17);
            indeksKolonaInputa.Add(18);
            indeksKolonaInputa.Add(19);
            indeksKolonaInputa.Add(20);

            // isNoble
            indeksKolonaInputa.Add(26);

            // numDeadRelations
            indeksKolonaInputa.Add(28);

            // house
            indeksKolonaInputa.Add(14);

            List <int> indeksKolonaOutputa = new List <int>();
            // isAlive
            indeksKolonaOutputa.Add(32);

            FileDAO fileDAO = new FileDAO(indeksKolonaInputa, indeksKolonaOutputa, 20);

            #endregion

            #region Vektori za inpute

            List <List <double> > X = new List <List <double> >();
            X = fileDAO.X;

            #endregion

            #region Vektori za outpute

            List <List <double> > Y = new List <List <double> >();
            Y = fileDAO.Y;

            #endregion

            #region Kreiranje neuronske mreze

            NeuralNetwork network = new NeuralNetwork();
            network.Add(new NeuralLayer(X[0].Count, 2, "sigmoid")); // X[0], ali moze i X[bilo koji idx], bitno je da tako dobijem broj ulaza
            network.Add(new NeuralLayer(2, 1, "sigmoid"));

            #endregion

            #region Fitovanje

            Console.WriteLine("Obuka pocela.");
            network.fit(X, Y, 0.1, 0.9, 500);
            Console.WriteLine("Kraj obuke.");

            #endregion

            #region Skor koji postize mreza

            Score score = new Score();
            score.giveMeScore(fileDAO, network);

            #endregion
        }
コード例 #5
0
        static void Main(string[] args)
        {
            NeuralNetwork network = new NeuralNetwork();

            network.Add(new NeuralLayer(4, 2, "sigmoid"));
            network.Add(new NeuralLayer(2, 1, "sigmoid"));

            List <int> lotArea   = new List <int>();
            List <int> yearBuilt = new List <int>();
            Dictionary <String, int> mapNeighbourhood = new Dictionary <String, int>();
            List <int>    listNeighbourhood           = new List <int>();
            List <double> listBldgType = new List <double>();//5 razlicitih vrsta
            List <int>    salePrice    = new List <int>();

            String[] dataLines = File.ReadAllLines(@"./../../train.csv");
            dataLines = dataLines.Skip(1).ToArray();

            foreach (String linija in dataLines)
            {
                string[] parts = linija.Split(',');
                lotArea.Add(int.Parse(parts[(int)Header.LotArea]));
                yearBuilt.Add(int.Parse(parts[(int)Header.YearBuilt]));

                String neighbourhood = parts[(int)Header.Neighborhood];
                if (!neighbourhood.Equals(""))
                {
                    if (!mapNeighbourhood.ContainsKey(neighbourhood))
                    {
                        mapNeighbourhood.Add(neighbourhood, mapNeighbourhood.Count);
                        listNeighbourhood.Add(mapNeighbourhood.Count);
                    }
                    else
                    {
                        listNeighbourhood.Add(mapNeighbourhood[neighbourhood]);
                    }
                }
                else
                {
                    listNeighbourhood.Add(mapNeighbourhood.Count);
                }

                //listBldgType
                String BldgType = parts[(int)Header.BldgType];
                if (BldgType.Equals("1Fam"))
                {
                    listBldgType.Add(0);
                }
                else if (BldgType.Equals("2fmCon"))
                {
                    listBldgType.Add(0.25);
                }
                else if (BldgType.Equals("Duplex"))
                {
                    listBldgType.Add(0.5);
                }
                else if (BldgType.Equals("Twnhs"))
                {
                    listBldgType.Add(0.75);
                }
                else if (BldgType.Equals("TwnhsE"))
                {
                    listBldgType.Add(1);
                }

                salePrice.Add(int.Parse(parts[(int)Header.SalePrice]));
            }
            List <double> lotAreaNormalizovani           = normalizacijaInt(lotArea);
            List <double> yearBuiltNormalizovani         = normalizacijaInt(yearBuilt);
            List <double> salePriceNormalizovani         = normalizacijaInt(salePrice);
            List <double> listNeighbourhoodNormalizovani = normalizacijaInt(listNeighbourhood);

            List <List <double> > X = new List <List <double> >();
            List <List <double> > Y = new List <List <double> >();

            // prolazimo kroz sve likove
            for (int i = 0; i < 1167; i++)
            {
                double[] xTemp = { lotAreaNormalizovani[i], yearBuiltNormalizovani[i], listNeighbourhoodNormalizovani[i], listBldgType[i] };
                X.Add(xTemp.ToList());


                double[] yTemp = { (double)salePriceNormalizovani[i] };
                Y.Add(yTemp.ToList());
            }

            Console.WriteLine("Obuka pocela");
            network.fit(X, Y, 0.1, 0.9, 250);

            Console.WriteLine("Gotova obuka");

            int tacnoPrediktovanih = 0;
            int brojPrediktovanih  = 0;

            for (int i = 1167; i < 1459; i++)
            {
                brojPrediktovanih++;
                double[] x1             = { lotAreaNormalizovani[i], yearBuiltNormalizovani[i], listNeighbourhoodNormalizovani[i], listBldgType[i] };
                double   predictedPrice = network.predict(x1.ToList())[0];
                double   realPrice      = salePriceNormalizovani[i];
                Console.WriteLine("prediktovana vrednost je " + predictedPrice + "  stvarna je " + salePriceNormalizovani[i]);
                double tacnost = (predictedPrice * 100) / realPrice;
                Console.WriteLine(tacnost);
                if (tacnost >= 80 && tacnost <= 120)
                {
                    tacnoPrediktovanih++;
                }
            }
            Console.WriteLine("Tacnost: " + (tacnoPrediktovanih * 100) / brojPrediktovanih + "%");
            Console.ReadLine();



            List <double> normalizacijaInt(List <int> listaVrednosti)
            {
                List <double> noramlizovanaLista = new List <double>();

                double dataMax = listaVrednosti.Max();
                double dataMin = listaVrednosti.Min();

                //  Console.WriteLine("Maksimalna vrendost je" + dataMax);
                //Console.WriteLine("Minimalna vrendost je" + dataMin);

                foreach (double vrednost in listaVrednosti)
                {
                    noramlizovanaLista.Add((vrednost - dataMin) / (dataMax - dataMin));
                    // Console.WriteLine("Minimalna vrendost je" + (vrednost - dataMin) / (dataMax - dataMin));
                }
                return(noramlizovanaLista);
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            #region Podesavanja koje cemo kolone ucitavati

            List <int> indeksKolonaInputa = new List <int>();

            // ulazi za pojavljivanje u knjigama
            indeksKolonaInputa.Add(16);
            indeksKolonaInputa.Add(17);
            indeksKolonaInputa.Add(18);
            indeksKolonaInputa.Add(19);
            indeksKolonaInputa.Add(20);

            // muski ili zensko ulaz
            indeksKolonaInputa.Add(7);
            // popularnost ulaz
            indeksKolonaInputa.Add(31);

            // plemicko poreklo ulaz
            indeksKolonaInputa.Add(26);

            // num dead relations ulaz
            indeksKolonaInputa.Add(28);

            // porodica kojoj pripada
            indeksKolonaInputa.Add(14);

            List <int> indeksKolonaOutputa = new List <int>();
            // isAlive ulaz
            indeksKolonaOutputa.Add(32);

            FileDAO fileDAO = new FileDAO(indeksKolonaInputa, indeksKolonaOutputa, 20);
            // fileDAO.imaKategorickihAtributa
            // fileDAO.getKategorickeAtribute

            #endregion


            #region Vektori za inpute

            List <List <double> > X = new List <List <double> >();
            X = fileDAO.X;

            #endregion

            #region Vektori za outpute

            List <List <double> > Y = new List <List <double> >();
            Y = fileDAO.Y;

            #endregion

            #region Kreiranje neuronske mreze

            NeuralNetwork network = new NeuralNetwork();
            network.Add(new NeuralLayer(X[0].Count, 4, "sigmoid")); // X[0], ali moze i X[bilo koji idx], bitno je da tako dobijem broj ulaza
            network.Add(new NeuralLayer(4, 2, "sigmoid"));
            network.Add(new NeuralLayer(2, 1, "sigmoid"));

            #endregion

            #region Fitovanje

            Console.WriteLine("Obuka pocela.");
            network.fit(X, Y, 0.1, 0.9, 10);
            Console.WriteLine("Kraj obuke.");

            #endregion

            #region Predikcija

            Score score = new Score();

            score.scoreModel(fileDAO, network);

            #endregion
        }
コード例 #7
0
        static void Main(string[] args)
        {
            string[] lines = File.ReadAllLines("@./../../../../../novi.csv");

            lines = lines.Skip(1).ToArray( );
            //ulazi
            List <int> typeList = new List <int>( );
            Dictionary <String, int> TypeDict           = new Dictionary <String, int>( );
            List <double>            oldBalanceOrgList  = new List <double>( );
            List <double>            newbalanceOrigList = new List <double>( );
            List <double>            oldBalanceDestList = new List <double>( );
            List <double>            newbalanceDestList = new List <double>( );
            List <double>            amountList         = new List <double>( );
            //izlaz
            List <int> isFraudList = new List <int>( );


            foreach (string line in lines)
            {
                string[] attr = line.Split(',');

                String p = attr[(int)FirstLine.type];
                if (TypeDict.ContainsKey(p))
                {
                    typeList.Add(TypeDict[p]);
                }
                else
                {
                    TypeDict[p] = TypeDict.Count;
                    typeList.Add(TypeDict[p]);
                }
                oldBalanceOrgList.Add(double.Parse(attr[(int)FirstLine.oldbalanceOrg]));
                newbalanceOrigList.Add(double.Parse(attr[(int)FirstLine.newbalanceOrig]));
                oldBalanceDestList.Add(double.Parse(attr[(int)FirstLine.oldbalanceDest]));
                newbalanceDestList.Add(double.Parse(attr[(int)FirstLine.newbalanceDest]));
                amountList.Add(double.Parse(attr[(int)FirstLine.amount]));

                isFraudList.Add(int.Parse(attr[(int)FirstLine.isFraud]));
            }

            //normalizacije
            double max = oldBalanceOrgList.Max( );

            for (int i = 0; i < oldBalanceOrgList.Count; i++)
            {
                oldBalanceOrgList[i] /= max;
            }

            max = newbalanceOrigList.Max( );
            for (int i = 0; i < newbalanceOrigList.Count; i++)
            {
                newbalanceOrigList[i] /= max;
            }

            max = oldBalanceDestList.Max( );
            for (int i = 0; i < oldBalanceDestList.Count; i++)
            {
                oldBalanceDestList[i] /= max;
            }

            max = newbalanceDestList.Max( );
            for (int i = 0; i < newbalanceDestList.Count; i++)
            {
                newbalanceDestList[i] /= max;
            }

            max = amountList.Max( );
            for (int i = 0; i < amountList.Count; i++)
            {
                amountList[i] /= max;
            }

            NeuralNetwork network = new NeuralNetwork( );

            network.Add(new NeuralLayer(6, 6, "sigmoid"));
            network.Add(new NeuralLayer(6, 1, "sigmoid"));

            List <List <double> > X = new List <List <double> >( );
            List <List <double> > Y = new List <List <double> >( );

            for (int i = 0; i < oldBalanceOrgList.Count; i++)
            {
                if (i % 5 != 0)
                {
                    double[] xTemp = { (double)typeList[i], (double)oldBalanceOrgList[i], (double)newbalanceOrigList[i], (double)oldBalanceDestList[i], (double)newbalanceDestList[i], (double)amountList[i] };
                    X.Add(xTemp.ToList( ));

                    double[] yTemp = { (double)isFraudList[i] };
                    Y.Add(yTemp.ToList( ));
                }
            }

            Console.WriteLine("obuka");
            network.fit(X, Y, 0.1, 0.9, 100);
            Console.WriteLine("done");

            //int x = (int)Math.Ceiling(oldBalanceOrgList.Count * 0.5);
            int x   = 0;
            int ok1 = 0;
            int ok0 = 0;
            int uk1 = 0;
            int uk0 = 0;

            for (int i = x; i < oldBalanceDestList.Count; i++)
            {
                if (i % 5 == 0)
                {
                    double[] x1 = { typeList[i], oldBalanceOrgList[i], newbalanceOrigList[i], oldBalanceDestList[i], newbalanceDestList[i], amountList[i] };
                    if (isFraudList[i] == 0)
                    {
                        uk0++;
                        if (network.predict(x1.ToList( ))[0] < 0.5)
                        {
                            ok0++;
                        }
                    }
                    else if (isFraudList[i] == 1)
                    {
                        uk1++;
                        if (network.predict(x1.ToList( ))[0] >= 0.5)
                        {
                            ok1++;
                        }
                    }
                }
            }

            Console.WriteLine("OK 0: " + ok0 + "\nUkupno: " + uk0 + "\nProcenat pogodaka:" + 100 * ((double)ok0 / uk0) + "\n");
            Console.WriteLine("OK 1: " + ok1 + "\nUkupno: " + uk1 + "\nProcenat pogodaka:" + 100 * ((double)ok1 / uk1) + "\n");
            Console.WriteLine("OK UkUPNO: " + (ok1 + ok0) + "\nUkupno: " + (uk0 + uk1) + "\nProcenat pogodaka:" + 100 * ((double)(ok1 + ok0) / (uk0 + uk1)) + "\n");

            Console.ReadLine( );
        }
コード例 #8
0
        static void Main(string[] args)
        {
            #region Ucitavanje data seta

            List <int> indeksKolonaInputa = new List <int>();

            // Gender
            indeksKolonaInputa.Add(1);

            // Married
            indeksKolonaInputa.Add(2);

            // education
            indeksKolonaInputa.Add(4);

            // ApplicantIncome
            indeksKolonaInputa.Add(6);

            //CoapplicantIncome
            indeksKolonaInputa.Add(7);

            //LoanAmount
            indeksKolonaInputa.Add(8);

            List <int> indeksKolonaOutputa = new List <int>();

            // Loan_Status
            indeksKolonaOutputa.Add(12);

            FileDAO fileDAO = new FileDAO(indeksKolonaInputa, indeksKolonaOutputa, 30); // 30 jer toliko zelim za test podatke

            #endregion

            #region Vektori za inpute

            List <List <double> > X = new List <List <double> >();
            X = fileDAO.X;

            #endregion

            #region Vektori za outpute

            List <List <double> > Y = new List <List <double> >();
            Y = fileDAO.Y;

            #endregion

            #region Kreiranje neuronske mreze

            NeuralNetwork network = new NeuralNetwork();
            network.Add(new NeuralLayer(X[0].Count, 2, "tanh")); // X[0], ali moze i X[bilo koji idx], bitno je da tako dobijem broj ulaza
            network.Add(new NeuralLayer(2, 1, "tanh"));

            #endregion

            #region Fitovanje

            Console.WriteLine("Obuka pocela.");
            network.fit(X, Y, 0.1, 0.9, 300);
            Console.WriteLine("Kraj obuke.");

            #endregion

            #region Skor koji postize mreza

            Score score = new Score();
            score.giveMeScore(fileDAO, network);

            #endregion
        }