问题
Thank you all for you help on my F# and C# question and am really beginning to enjoy the fruits of the learning. I have asked a question like this before and I know these are on the line of the purposes of this forum, but I think this is useful and would provide some help to all us F# data miners out there :-). I am utilizing Yin Zhu's WekaSharp for my experiments and am interested in the rates of computation between F# and C#. I have written a snippet based on his example in the F# and would like to make its like in C# but am not sure how to approach it. Yin Zhu has create the same code to access these functions from the C# called WekaCSharp but the example he provides does not really touch on this operation. I hate to keep bugging him with my menial questions so if anyone has the time and is willing here is the F# script:
(* K-Means cluster Algorithm *)
// load the data set
let sonar =
System.IO.Path.Combine(__SOURCE_DIRECTORY__, @"..\..\data\KDDCup99.arff")
|> Dataset.readArff
|> Dataset.setClassIndexWithLastAttribute
// set different parameters
let Cs = [0.01; 0.1; 1.; 10.; 50.; 100.; 500.; 1000.; 2000.; 5000. ]
// make the tasks with the parameter set
let tasks =
Cs
|> List.map (fun c -> Parameter.KNN.DefaultPara)
|> List.map (fun p -> CrossValidation(3, sonar, ClassifierType.KNN, p))
Profile.tic()
// the accuracy result
let results =
tasks
|> Eval.evalBulkClassify
|> List.map Eval.getAccuracy
Profile.toc("sequential time: ")
Profile.tic()
let resultsParallel =
tasks
|> Eval.evalBulkClassifyParallel
|> List.map Eval.getAccuracy
Profile.toc("parallel (PSeq) time: ")
Again, I apologize if I am streaching the intent of this forum but this would be greatly useful for all us learning to use Weka in .NET . Here is what I have so far:
class Program
{
static void Classify()
{
Instances dataSetForTrain = new Instances(new BufferedReader(
new FileReader(@"C:\Users\Deines\Documents\School\Software\WekaSharp2012\data\iris.arff")));
dataSetForTrain.setClassIndex(dataSetForTrain.numAttributes() - 1);
string options = @"-P 100 -S 1 -I 10 -W weka.classifiers.bayes.NaiveBayes -- -M 2 -V 0.0010 -N 3 -S 1 -L -1";
Bagging model = new Bagging();
model.setOptions(options.Split(' '));
model.buildClassifier(dataSetForTrain);
// test the instances from iris.arff
Instances dataSetForTest = new Instances(new BufferedReader(
new FileReader(@"C:\Users\Deines\Documents\School\Software\WekaSharp2012\data\iris.arff")));
dataSetForTest.setClassIndex(dataSetForTest.numAttributes() - 1);
for (int i = 0; i < dataSetForTest.numInstances(); i++)
{
var inst = dataSetForTest.instance(i);
int label = (int)model.classifyInstance(inst);
System.Console.WriteLine(label);
}
}
public static void Main(string[] args)
{
Classify();
}
}
Thank you very much.
来源:https://stackoverflow.com/questions/20204678/how-to-call-wekasharp-commands-from-c-sharp