golang是否具有等效功能,可以像在python中一样检查包/ go文件中是否存在函数。
set.seed(42)
#dataset<-read.csv(file.choose(),header=T,sep=";")
str(dataset)
dataset$NClaims[is.na(dataset$NClaims)]<-names(which.max(table(dataset$NClaims)))
dataset$ClaimReason<-NULL
dataset$ClaimNr<-NULL
dataset$ClaimDate<-NULL
dataset$ClaimYear<-NULL
dataset$Incurred<-NULL
dataset$Payments<-NULL
dataset$Reserve<-NULL
colSums(is.na(dataset))
dataset$ValidFrom<-NULL
dataset$ValidThru<-NULL
dataset$County<-NULL
dataset$Gender<-NULL
dataset$Make<-NULL
weights_info_gain <- information.gain(NClaims ~ ., data=dataset)
wgr = gain.ratio(NClaims ~ ., data=dataset)
mia <- cutoff.k(wgr, 20)
fia <- as.simple.formula(mia, "NClaims")
fitCtrl = trainControl(method="repeatedcv", number=5, repeats=3)
modelGLM = train(fia, data=dataset, method="glm", trControl=fitCtrl, metric="Accuracy",na.action = na.pass)
summary(modelGLM)
答案 0 :(得分:1)
从this帖子看来,这是不可能直接实现的。
您总是可以创建自己的软件包来搜索软件包文件,并检查该方法是否存在,如以上post's first answer所述。
答案 1 :(得分:0)
根据您的评论,听起来您可能只是在使用包含可用功能的地图。这是一个完整的示例:
package main
import (
"flag"
"fmt"
"os"
)
func main() {
var option string
var data string
flag.StringVar(&option, "option", "default", "The option to choose from")
flag.StringVar(&data, "data", "", "The data to use")
flag.Parse()
options := map[string]func(string) string{
"foo": func(data string) string {
fmt.Println("do something with data using option foo")
return data
},
"bar": func(data string) string {
fmt.Println("do something with data using option bar")
return data
},
"default": func(data string) string {
fmt.Println("do something with data using default option")
return data
},
}
method, found := options[option]
if !found {
fmt.Println("option is not available")
os.Exit(1)
}
result := method(data)
fmt.Println(result)
}
输出
$ go run main.go -data hello -option foo
do something with data using option foo
hello
$ go run main.go -data hello -option whatever
option is not available
$ go run main.go -data hello
do something with data using default option
hello