我用带线性核的支持向量机做了一个多类(3)分类。
对于这个任务,我使用
mlr
包裹。支持向量机来自
kernlab
包裹。
library(mlr)
library(kernlab)
print(filtered_task)
Supervised task: dtm
Type: classif
Target: target_lable
Observations: 1462
Features:
numerics factors ordered functionals
291 0 0 0
Missings: FALSE
Has weights: FALSE
Has blocking: FALSE
Has coordinates: FALSE
Classes: 3
negative neutral positive
917 309 236
Positive class: NA
lrn = makeLearner("classif.ksvm", par.vals = list(kernel = "vanilladot"))
mod = mlr::train(lrn, train_task)
现在我想知道哪些特性在每个类中的权重最高。知道怎么去吗?
此外,对于交叉验证结果,最好能得到每个类的特征权重。
rdesc = makeResampleDesc("CV",
iters = 10,
stratify = T)
set.seed(3)
r = resample(lrn, filtered_task, rdesc)
我知道有可能像下面这样计算特征重要性,这与蒙特卡罗迭代的交叉验证结果类似。
imp = generateFeatureImportanceData(task = train_task,
method = "permutation.importance",
learner = lrn,
nmc = 10)
但是,对于这个方法,我不能得到每个类的特性重要性,而只能得到总体重要性。
library(dplyr)
library(ggplot)
imp_data = melt(imp$res[, 2:ncol(imp$res)])
imp_data = imp_data %>%
arrange(-value)
imp_data[1:10,] %>%
ggplot(aes(x = reorder(variable, value), y = value)) +
geom_bar(stat = "identity", fill = "darkred") +
labs(x = "Features", y = "Permutation Importance") +
coord_flip() +
theme_minimal()