Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Where is Accord.NET AdaBoost Decide method? #843

Closed
HamidEbr opened this issue Sep 5, 2017 · 3 comments
Closed

Where is Accord.NET AdaBoost Decide method? #843

HamidEbr opened this issue Sep 5, 2017 · 3 comments

Comments

@HamidEbr
Copy link

HamidEbr commented Sep 5, 2017

I'm trying to use Accord.NET library for objects classification, but I failed to find any suitable examples and documentation is not enough to understand the process. My current code is


Predictor = new Boost<DecisionStump>();
AdaBoost<DecisionStump> Algo = new AdaBoost<DecisionStump>(Predictor, new ModelConstructor<DecisionStump>((double[] weights) => new DecisionStump(10)));
Algo.Run(inputs, outputs);

This code works well, but i want to use Decide method like other classifiers in accord.net, how can i do it?
It seems that the Adaboost had been left behind when most of the existing classifiers were upgraded to the .Decide() API last year!

Here is stackoverflow topic of this request!

@HamidEbr
Copy link
Author

HamidEbr commented Sep 5, 2017

I get accord.net source code and find Creation property that uses like

var model = Algo.Creation(double[] weights)

It seemed
model.Compute(double[] inputs)

works like Decide method! But i don`t know about weights in Creation method!? @Accord.NET

@cesarsouza
Copy link
Member

cesarsouza commented Sep 6, 2017

Hi @HamidEbr,

Sorry for the delay. I will post below an example on how the AdaBoost class can be used:

// Let's say we want to classify the following 2-dimensional 
// data samples into 2 possible classes, either true or false:
double[][] inputs =
{
    new double[] { 10, 42 },
    new double[] { 162, 96 },
    new double[] { 125, 20 },
    new double[] { 96, 6 },
    new double[] { 2, 73 },
    new double[] { 52, 51 },
    new double[] { 71, 49 },
};

// And those are their associated class labels
int[] outputs = 
{
    -1, -1, +1, +1, -1, -1, +1
};


// First, we create a classsifier using:
var classifier = new Boost<DecisionStump>();

// Now, we can create a AdaBoost learning algorithm as:
var teacher = new AdaBoost<DecisionStump>(classifier)
{
    Creation = (weights) =>
    {
        var stump = new DecisionStump(2);
        stump.Learn(inputs, outputs, weights);
        return stump;
    },

    // Train until:
    MaxIterations = 5,
    Tolerance = 1e-3
};

// Now, we can use the Run method to learn:
double error = teacher.Run(inputs, outputs); // error should be zero.

// Now, we can compute the model outputs for new samples using
int y = classifier.Compute(new double[] { 71, 48 }); // should be 1

The API will be updated to follow the .Learn/Decide interface for the next release. Thanks again for opening the issue!

Hope it helps,
Cesar

cesarsouza added a commit that referenced this issue Sep 7, 2017
Adding a new .Error property in ConfusionMatrix;
Adding named constructors to ConfusionMatrix to create matrices directly from classifiers, their inputs and expected outputs.

Updates:
 - GH-843: Where is Accord.NET AdaBoost Decide method?
 - GH-629: Add an Example for AdaBoost(TModel) Class
 - GH-424: Add an Example for AdaBoost(TModel) Class
 - GH-415: Add an Example for AdaBoost(TModel) Class
@cesarsouza
Copy link
Member

Added in 3.8.0. The new code examples can be found in the documentation pages for the AdaBoost meta-learning algorithm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants