本文整理汇总了Golang中github.com/xlvector/hector/algo.Classifier类的典型用法代码示例。如果您正苦于以下问题:Golang Classifier类的具体用法?Golang Classifier怎么用?Golang Classifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Classifier类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AlgorithmRunOnDataSet
func AlgorithmRunOnDataSet(classifier algo.Classifier, train_dataset, test_dataset *core.DataSet, pred_path string, params map[string]string) (float64, []*eval.LabelPrediction) {
if train_dataset != nil {
classifier.Train(train_dataset)
}
predictions := []*eval.LabelPrediction{}
var pred_file *os.File
if pred_path != "" {
pred_file, _ = os.Create(pred_path)
}
for _, sample := range test_dataset.Samples {
prediction := classifier.Predict(sample)
if pred_file != nil {
pred_file.WriteString(strconv.FormatFloat(prediction, 'g', 5, 64) + "\n")
}
predictions = append(predictions, &(eval.LabelPrediction{Label: sample.Label, Prediction: prediction}))
}
if pred_path != "" {
defer pred_file.Close()
}
auc := eval.AUC(predictions)
return auc, predictions
}
示例2: AlgorithmRun
func AlgorithmRun(classifier algo.Classifier, train_path string, test_path string, pred_path string, params map[string]string) (float64, []*eval.LabelPrediction, error) {
global, _ := strconv.ParseInt(params["global"], 10, 64)
train_dataset := core.NewDataSet()
err := train_dataset.Load(train_path, global)
if err != nil {
return 0.5, nil, err
}
test_dataset := core.NewDataSet()
err = test_dataset.Load(test_path, global)
if err != nil {
return 0.5, nil, err
}
classifier.Init(params)
auc, predictions := AlgorithmRunOnDataSet(classifier, train_dataset, test_dataset, pred_path, params)
return auc, predictions, nil
}
示例3: AlgorithmTest
func AlgorithmTest(classifier algo.Classifier, test_path string, pred_path string, params map[string]string) (float64, []*eval.LabelPrediction, error) {
global, _ := strconv.ParseInt(params["global"], 10, 64)
model_path, _ := params["model"]
classifier.Init(params)
if model_path != "" {
classifier.LoadModel(model_path)
} else {
return 0.0, nil, nil
}
test_dataset := core.NewDataSet()
err := test_dataset.Load(test_path, global)
if err != nil {
return 0.0, nil, err
}
auc, predictions := AlgorithmRunOnDataSet(classifier, nil, test_dataset, pred_path, params)
return auc, predictions, nil
}
示例4: AlgorithmTrain
func AlgorithmTrain(classifier algo.Classifier, train_path string, params map[string]string) error {
global, _ := strconv.ParseInt(params["global"], 10, 64)
train_dataset := core.NewDataSet()
err := train_dataset.Load(train_path, global)
if err != nil {
return err
}
classifier.Init(params)
classifier.Train(train_dataset)
model_path, _ := params["model"]
if model_path != "" {
classifier.SaveModel(model_path)
}
return nil
}