如何从 kernlab 中提取训练误差?

How can I extract training error from kernlab?

以下代码:

portuguese_scores = read.table("https://raw.githubusercontent.com/JimGorman17/Datasets/master/student-por.csv",sep=";",header=TRUE)
portuguese_scores <- portuguese_scores[,!names(portuguese_scores) %in% c("school", "age", "G1", "G2")]
median_score <- summary(portuguese_scores$G3)['Median']
portuguese_scores$score_gte_than_median <- as.factor(median_score<=portuguese_scores$G3)
portuguese_scores <- portuguese_scores[,!names(portuguese_scores) %in% c("G3")]

set.seed(123)

train_sample <- sample(nrow(portuguese_scores), .9 * nrow(portuguese_scores))
port_train <- portuguese_scores[train_sample,]
port_test <- portuguese_scores[-train_sample,]

library(kernlab)
median_classifier <- ksvm(score_gte_than_median ~ ., data=port_train, kernel="vanilladot")
median_classifier

生成以下输出:

Support Vector Machine object of class "ksvm" 

SV type: C-svc  (classification) 
 parameter : cost C = 1 

Linear (vanilla) kernel function. 

Number of Support Vectors : 320 

Objective Function Value : -300.32 
Training error : 0.208904

如何将 'Training error' 的值提取到变量中?

尝试

median_classifier@error
[1] 0.2089041

这是一个 S4 对象。请参阅有关 ksvm-class 插槽的文档。 ?'ksvm-class'