Как построить две кривые ROC на одном участке с помощью пакета PRECREC
Я использую precrec
пакет для оценки нескольких моделей и построения ROC и PR-ROC.
Я хочу провести сравнение моделей в конце, но, похоже, я не могу построить обе модели на одном графике.
Вот моя попытка:
library(precrec)
library(caret)
library(e1071)
classifier = svm(formula = Class ~ .,
data = train_smote_maison,
type = 'C-classification',
kernel = "linear",
probability = TRUE,
cross = 3,
cost = 1)
test_svm_plot = df[train.test.split == 2,]
predictions_svm2 <- predict(classifier,newdata = test_svm_plot, probability=T)
svm2_predict_obj <- mmdata(as.numeric(predictions_svm2),test_svm_plot$Class)
svm2_perfromance <- evalmod(svm2_predict_obj)
classifier_logreg <- glm(data = train, family = "binomial",
formula = Class ~ .)
test_glm = test
test_glm_plot = df[train.test.split == 2,]
predictions_logreg <- predict(classifier_logreg,newdata = test_glm, type = "response")
logreg_predict_obj <- mmdata(predictions_logreg,test_glm$Class)
logreg_performance <- evalmod(mdat = logreg_predict_obj)
plot(svm2_perfromance, "ROC")
plot(logreg_performance, "ROC", add=TRUE, col='red')
Кто-нибудь знает, как убедиться, что я могу получить оба ROC на одном участке?
Заранее спасибо.
2 ответа
Вы можете использовать "fortify", чтобы создать фрейм данных ggplot для каждого объекта производительности, затем объединить (rbind) их и построить график с помощью ggplot.
library(ggplot2)
svm2_df <- fortify(svm2_perfromance)
logreg_df <- fortify(logreg_performance)
svm2_df$classifier <- "svm2"
logreg_df$classifier <- "logreg"
performance_df <- rbind(svm2_df, logreg_df)
roc <- performance_df[performance_df$classifier == "ROC",]
ggplot(roc, aes(x=x, y=y, group = classifier)) + geom_line(aes(color = classifier))
import plotly.express as px
x = ["Классификатор K-соседей", "Классификатор случайного леса", "Логистическая регрессия", "Классификатор XGBoost"]
y = [knn_accuracy 100, rf_accuracy 100, lr_accuracy 100, xgb_accuracy 100]
fig = px.bar(x=x, y=y, color=x, title="Сравнение моделей - точность модели", labels={'x': 'Модель', 'y': 'Точность модели'},) рис.шоу()