public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double C = 0.9;
        double epsilon = 1e-3;

        Math.init_random(17);
        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat");

        double[] trainlab = Load.load_labels("../data/label_train_twoclass.dat");

        RealFeatures feats_train = new RealFeatures();
        feats_train.set_feature_matrix(traindata_real);
        RealFeatures feats_test = new RealFeatures();
        feats_test.set_feature_matrix(testdata_real);

        BinaryLabels labels = new BinaryLabels(trainlab);

        LibLinear svm = new LibLinear(C, feats_train, labels);
        svm.set_liblinear_solver_type(LIBLINEAR_SOLVER_TYPE.L2R_L2LOSS_SVC_DUAL);
        svm.set_epsilon(epsilon);
        svm.set_bias_enabled(true);
        svm.train();
        svm.set_features(feats_test);
        double[] out_labels = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

        foreach(double item in out_labels) {
            Console.Write(item);
        }

        modshogun.exit_shogun();
    }
    static void Main(string[] argv)
    {
        modshogun.init_shogun_with_defaults();
        double C = 0.9;
        double epsilon = 1e-3;

        org.shogun.Math.init_random(17);
        DoubleMatrix traindata_real = Load.load_numbers(".../data/fm_train_real.dat");
        DoubleMatrix testdata_real = Load.load_numbers("../data/toy/fm_test_real.dat");

        DoubleMatrix trainlab = Load.load_labels("../data/label_train_twoclass.dat");

        RealFeatures feats_train = new RealFeatures();
        feats_train.set_feature_matrix(traindata_real);
        RealFeatures feats_test = new RealFeatures();
        feats_test.set_feature_matrix(testdata_real);

        Labels labels = new Labels(trainlab);

        LibLinear svm = new LibLinear(C, feats_train, labels);
        svm.set_liblinear_solver_type(L2R_L2LOSS_SVC_DUAL);
        svm.set_epsilon(epsilon);
        svm.set_bias_enabled(true);
        svm.train();
        svm.set_features(feats_test);
        DoubleMatrix out_labels = svm.apply().get_labels();
        Console.WriteLine(out_labels.ToString());

        modshogun.exit_shogun();
    }
Example #3
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double C       = 0.9;
        double epsilon = 1e-3;

        Math.init_random(17);
        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");

        double[] trainlab = Load.load_labels("../data/label_train_twoclass.dat");

        RealFeatures feats_train = new RealFeatures();

        feats_train.set_feature_matrix(traindata_real);
        RealFeatures feats_test = new RealFeatures();

        feats_test.set_feature_matrix(testdata_real);

        BinaryLabels labels = new BinaryLabels(trainlab);

        LibLinear svm = new LibLinear(C, feats_train, labels);

        svm.set_liblinear_solver_type(LIBLINEAR_SOLVER_TYPE.L2R_L2LOSS_SVC_DUAL);
        svm.set_epsilon(epsilon);
        svm.set_bias_enabled(true);
        svm.train();
        svm.set_features(feats_test);
        double[] out_labels = LabelsFactory.to_binary(svm.apply()).get_labels();

        foreach (double item in out_labels)
        {
            Console.Write(item);
        }
    }
        private void ClassifierList_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right && SelectedItem != null)
            {
                Classifier classifier = SelectedItem as Classifier;
                if (classifier == null)
                {
                    throw new NullReferenceException("Failed to cast classifier item from list");
                }

                string updateWindowTitle = "Updating " + classifier.GetType().Name + "...";

                if (classifier is LibLinear)
                {
                    LibLinear   liblinear = classifier as LibLinear;
                    DynamicForm f         = new DynamicForm("Set LibLinear parameters", DynamicForm.CloseButtons.OkCancel);
                    f.AddCheckBox("Run feature selection:", ContentAlignment.MiddleRight, liblinear.RunFeatureSelection, "run_feature_selection");
                    f.AddDropDown("Positive weighting:", Enum.GetValues(typeof(LibLinear.PositiveClassWeighting)), liblinear.Weighting, "positive_weighting", true);
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        liblinear.RunFeatureSelection = f.GetValue <bool>("run_feature_selection");
                        liblinear.Weighting           = f.GetValue <LibLinear.PositiveClassWeighting>("positive_weighting");
                    }
                }
                else if (classifier is SvmRank)
                {
                    SvmRank     svmRank = classifier as SvmRank;
                    DynamicForm f       = new DynamicForm("Set SvmRank parameters", DynamicForm.CloseButtons.OkCancel);
                    f.AddNumericUpdown("c:", (decimal)svmRank.C, 3, decimal.MinValue, decimal.MaxValue, (decimal)0.01, "c");
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        try { svmRank.C = Convert.ToSingle(f.GetValue <decimal>("c")); }
                        catch (Exception ex) { MessageBox.Show("Invalid value for C:  " + ex.Message); }
                    }
                }
                else if (classifier is RandomForest)
                {
                    RandomForest randomForest = classifier as RandomForest;
                    DynamicForm  f            = new DynamicForm("Set RandomForest parameters", DynamicForm.CloseButtons.OkCancel);
                    f.AddNumericUpdown("Number of trees:", randomForest.NumTrees, 0, 1, decimal.MaxValue, 1, "ntree");
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        randomForest.NumTrees = Convert.ToInt32(f.GetValue <decimal>("ntree"));
                    }
                }
                else if (classifier is AdaBoost)
                {
                    AdaBoost    adaBoost = classifier as AdaBoost;
                    DynamicForm f        = new DynamicForm("Set AdaBoost parameters", DynamicForm.CloseButtons.OkCancel);
                    f.AddNumericUpdown("Number of iterations:", adaBoost.Iterations, 0, 1, decimal.MaxValue, 1, "iterations");
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        adaBoost.Iterations = Convert.ToInt32(f.GetValue <decimal>("iterations"));
                    }
                }
            }
        }