2015-05-08 3 views
4

Я пытаюсь использовать adaboost (или повышение) в Accord.Net. Я попробовал версию примера, приведенного на https://github.com/accord-net/framework/wiki/Classification для деревьев решений и хорошо работает со следующим кодом:Используйте AdaBoost (Boosting) с Accord.Net

'' Creates a matrix from the entire source data table 
Dim data As DataTable = CType(DataView.DataSource, DataTable) 

'' Create a new codification codebook to 
'' convert strings into integer symbols 
Dim codebook As New Codification(data) 

'' Translate our training data into integer symbols using our codebook: 
Dim symbols As DataTable = codebook.Apply(data) 
Dim inputs As Double()() = symbols.ToArray(Of Double)("Outlook", "Temperature", "Humidity", "Wind") 
Dim outputs As Integer() = symbols.ToArray(Of Integer)("PlayTennis") 

'' Gather information about decision variables 
Dim attributes() As DecisionVariable = {New DecisionVariable("Outlook", 3), New DecisionVariable("Temperature", 3), _ 
    New DecisionVariable("Humidity", 2), New DecisionVariable("Wind", 2)} 

Dim classCount As Integer = 2 '' 2 possible output values for playing tennis: yes or no 

''Create the decision tree using the attributes and classes 
tree = New DecisionTree(attributes, classCount) 

'' Create a new instance of the ID3 algorithm 
Dim Learning As New C45Learning(tree) 

'' Learn the training instances! 
Learning.Run(inputs, outputs) 

Dim aa As Integer() = codebook.Translate("D1", "Rain", "Mild", "High", "Weak") 

Dim ans As Integer = tree.Compute(aa) 

Dim answer As String = codebook.Translate("PlayTennis", ans) 

Теперь я хочу addapt этот код, чтобы использовать AdaBoost или повышение на более сложные примеры. Я попытался следующие, добавив следующее в коде выше:

Dim Booster As New Boost(Of DecisionStump)() 

Dim Learn As New AdaBoost(Of DecisionStump)(Booster) 
Dim weights(inputs.Length - 1) As Double 
For i As Integer = 0 To weights.Length - 1 
    weights(i) = 1.0/weights.Length 
Next 

Learn.Creation = New ModelConstructor(Of DecisionStump)(x=>tree.Compute(x)) 
Dim Err As Double = Learn.Run(inputs, outputs, weights) 

Проблема, кажется, что линия:

Learn.Creation = New ModelConstructor(Of DecisionStump)(x=>tree.Compute(x)) 

Как я могу использовать AdaBoost или повышение в Accord.Net? Как я могу настроить свой код, чтобы он работал? Вся помощь будет оценена.

+0

Определяли ли вы «x»?, Алгоритм может не понравиться неопределенной переменной, если он не определен. Рассматривая специфический набор данных Ying-Yang, вы можете использовать модельную кластеризацию (модели смеси Гаусса) и, вероятно, лучше, чем любой из описанных методов. Кроме того, SVM с ядром радиальной базовой функции (RBF) должен преуспеть. (Я не рассматривал используемую методологию SVM). – wrtsvkrfm

ответ

0

Это поздний ответ, но для тех, кто может оказаться полезным в будущем, начиная с версии 3.8.0, усиленный Дерево решений можно узнать с помощью Accord.NET Framework, как показано ниже:

// This example shows how to use AdaBoost to train more complex 
// models than a simple DecisionStump. For example, we will use 
// it to train a boosted Decision Trees. 

// Let's use some synthetic data for that: The Yin-Yang dataset is 
// a simple 2D binary non-linear decision problem where the points 
// belong to each of the classes interwine in a Yin-Yang shape: 
var dataset = new YinYang(); 
double[][] inputs = dataset.Instances; 
int[] outputs = Classes.ToZeroOne(dataset.ClassLabels); 

// Create an AdaBoost for Logistic Regression as: 
var teacher = new AdaBoost<DecisionTree>() 
{ 
    // Here we can specify how each regression should be learned: 
    Learner = (param) => new C45Learning() 
    { 
     // i.e. 
     // MaxHeight = 
     // MaxVariables = 
    }, 

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

// Now, we can use the Learn method to learn a boosted classifier 
Boost<DecisionTree> classifier = teacher.Learn(inputs, outputs); 

// And we can test its performance using (error should be 0.11): 
double error = ConfusionMatrix.Estimate(classifier, inputs, outputs).Error; 

// And compute a decision for a single data point using: 
bool y = classifier.Decide(inputs[0]); // result should false 

 Смежные вопросы

  • Нет связанных вопросов^_^