我试着理解图形和图形学习者之间的区别。我可以用图表来表示$train和$predict。但是我需要“包装器”来使用行选择和分数(见下面的代码)。
有什么东西可以做的图形,而不是同时是一个学习者?(在使用gr的代码中,而不是在glrn中?
gr = po(lrn("classif.kknn", predict_type = "prob"),
param_vals = list(k = 10, distance=2, kernel='rectangular' )) %>>%
po("threshold", param_vals = list(thresholds = 0.6))
glrn = GraphLearner$new(gr) # build Graph Learner from graph
glrn$train(task, row_ids=1:300) # n.b.: We need to construct a graph learner in order to use row_ids etc.
predictions=glrn$predict(task,row_ids = 327:346) # would not work with gr
predictions$score(msr("classif.acc"))
predictions$print()发布于 2021-04-09 19:57:08
GraphLearner总是包装一个以单个Task作为输入并生成单个Prediction作为输出的Graph。然而,Graph可以表示任何类型的计算,甚至可以接受多个输入/产生多个输出。在构建一个对单个任务进行训练的Graph时,您通常会使用这些中间构建块,给出一个预测,然后将其包装为一个GraphLearner。
在某些情况下,如果您做了某种预处理,例如计算或PCA,并且也应该应用于某种不可见的数据(即应用与PCA相同的旋转),这也可能是有帮助的,尽管您的过程作为一个整体并不是经典的机器学习,它为预测提供了一个模型:
data <- tsk("pima")
trainingset <- sample(seq(0, 1, length.out = data$nrow) < 2/3)
data.t <- data$clone(deep = TRUE)$filter(which(trainingset))
data.p <- data$clone(deep = TRUE)$filter(which(!trainingset))
# Operation:
# 1. impute missing values with mean of non-missings in same column
# 2. rotate to principal component axes
imputepca <- po("imputemean") %>>% po("pca")
# Need to take element 1 of result here: 'Graph' could have multiple
# outputs and therefore returns a list. In our case we only have one
# result that we care about.
rotated.t <- imputepca$train(data.t)[[1]]
rotated.t$head(2)
#> diabetes PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8
#> 1: pos -4.744963 27.76824 -5.2432401 9.817512 -9.042784 0.4979002 0.4574355 -0.1058608
#> 2: neg 6.341357 -37.18033 -0.1210501 3.731123 -1.451952 3.6890699 2.3901156 0.0755521
# this data is imputed using the column means of the training data, and then
# rotated by the same rotation as the training data.
rotated.p <- imputepca$predict(data.p)[[1]]
rotated.p$head(2)
#> diabetes PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8
#> 1: pos -11.535952 9.358736 25.1073705 4.761627 -23.313410 -9.743428 3.412071 -1.6403521
#> 2: neg 1.189971 -7.098455 -0.2785817 -3.280845 -0.281516 -2.277787 -6.746323 0.3434535但是,由于mlr3pipelines主要是为mlr3构建的,这是为了使Learners能够被训练和重放等等,所以您通常会在GraphLearner中封装您的Graphs。
https://stackoverflow.com/questions/67023825
复制相似问题