1 Star 0 Fork 0

JoyAllen/config-selector

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
svm-handle.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"fmt"
"github.com/ewalker544/libsvm-go"
"os"
)
func makeTrainData(conc int, latency float64, filename string) {
//每执行一次,添加一次
fp, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0777)
if err != nil {
fmt.Println(err)
return
}
defer fp.Close()
fp.WriteString(fmt.Sprintf("%d 1:%f\n", conc, latency))
}
func svmTrain(trainDataFile string) string {
param := libSvm.NewParameter() // Create a parameter object with default values
param.KernelType = libSvm.POLY // Use the polynomial kernel
model := libSvm.NewModel(param) // Create a model object from the parameter attributes
// Create a problem specification from the training data and parameter attributes
problem, _ := libSvm.NewProblem(trainDataFile, param)
model.Train(problem) // Train the model from the problem specification
modelFile := trainDataFile + ".model"
model.Dump(modelFile)
return modelFile
}
func svmPredicting(modelFile string) float64 {
// Create a model object from the model file generated from training
model := libSvm.NewModelFromFile(modelFile)
x := make(map[int]float64)
// Populate x with the test vector
predictLabel := model.Predict(x) // Predicts a float64 label given the test vector
return predictLabel
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/joyallen/config-selector.git
[email protected]:joyallen/config-selector.git
joyallen
config-selector
config-selector
master

搜索帮助