我的数据(内部)具有3个类和3个自变量(类型,份额,值)的因变量(类)。我将其划分为训练和测试数据,然后将多类逻辑回归应用于训练数据集和对测试数据集的预测。我的准确率是34%。现在,我想使用“ multiclass.roc函数”计算曲线下的面积,但是我做不到。
library(pROC)
library(nnet)
summary(insider)
#class type shares value
buyuk:200000 al :106805 Min. :0.000e+00 Min. :0.000e+00
kucuk:150000 sat:393195 1st Qu.:3.000e+02 1st Qu.:6.651e+03
orta :150000 Median :1.250e+03 Median :2.810e+04
Mean :2.963e+07 Mean :5.071e+11
3rd Qu.:6.800e+03 3rd Qu.:1.793e+05
Max. :5.774e+12 Max. :9.677e+14
set.seed(7267166)
trainIndex=createDataPartition(insider$class, p=0.7)$Resample1
train=insider[trainIndex, ]
test=insider[-trainIndex, ]
model <- nnet::multinom(class ~., data = train)
predicted.classes <- model %>% predict(test)
mean(predicted.classes == test$class)
[1] 0.338
multiclass.roc(test$class, predict(model, test, type = 'prob'))
#Error in roc.default(response, predictor, levels = X, percent = percent, :
Response and predictor must be vectors of the same length.
In addition: Warning message:
In roc.default(response, predictor, levels = X, percent = percent, :
Deprecated use a matrix as predictor. Unexpected results may be produced,
please pass a numeric vector.