2013-06-29 41 views
0

我使用libsvm C#wrapper for svr来预测薪水.predicted结果是错误的。 libsvm为所有的实例赋予相同的值。我有预制形式的网格搜索参数选择。我可以在这里解决这个问题是我的代码。libsvm为所有数据集实例预测相同的值

Problem train = Problem.Read(@"H:\test.csv"); 
Problem test = Problem.Read(@"H:\testsvmf1.csv"); 


//For this example (and indeed, many scenarios), the default 
//parameters will suffice. 
Parameter parameters = new Parameter(); 
//double C; 
//double Gamma; 


//This will do a grid optimization to find the best parameters 
//and store them in C and Gamma, outputting the entire 
//search to params.txt. 

ParameterSelection.Grid(train, parameters, @"H:\params.txt", out C, out Gamma); 
parameters.C = 512; 
parameters.Gamma = 0.5; 
parameters.SvmType = SvmType.NU_SVR; 
double cv = Training.PerformCrossValidation(train,parameters,10); 

Console.Write(cv); 
//Train the model using the optimal parameters. 

Model model = Training.Train(train, parameters); 


//Perform classification on the test data, putting the 
//results in results.txt. 

Prediction.Predict(test, @"H:\resultsnew1.txt", model, false); 

} 

public static SvmType NU_SVR { get; set; } 

回答

4

它看起来像您执行网格搜索来调整你参数,但你手动设置为固定值(C = 512,伽玛= 0.5)。固定参数用于训练...

相关问题