- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 XGBoost 构建我的预测模型:
setDT(train)
setDT(test)
labels <- train$Goal
ts_label <- test$Goal
new_tr <- model.matrix(~.+0,data = train[,-c("Goal"),with=F])
new_ts <- model.matrix(~.+0,data = test[,-c("Goal"),with=F])
labels <- as.numeric(labels)-1
ts_label <- as.numeric(ts_label)-1
dtrain <- xgb.DMatrix(data = new_tr,label = labels)
dtest <- xgb.DMatrix(data = new_ts,label=ts_label)
params <- list(booster = "gbtree", objective = "binary:logistic", eta=0.3, gamma=0, max_depth=6, min_child_weight=1, subsample=1, colsample_bytree=1)
xgb1 <- xgb.train(params = params, data = dtrain, nrounds = 291, watchlist = list(val=dtest,train=dtrain), print_every_n = 10,
early_stop_round = 10, maximize = F , eval_metric = "error")
xgbpred <- predict(xgb1,dtest)
xgbpred <- ifelse(xgbpred > 0.5,1,0)
confusionMatrix(xgbpred, ts_label)
Confusion Matrix and Statistics
Reference
Prediction 0 1
0 1904 70
1 191 2015
Accuracy : 0.9376
95% CI : (0.9298, 0.9447)
No Information Rate : 0.5012
P-Value [Acc > NIR] : < 0.00000000000000022
Kappa : 0.8751
Mcnemar's Test P-Value : 0.0000000000001104
Sensitivity : 0.9088
Specificity : 0.9664
Pos Pred Value : 0.9645
Neg Pred Value : 0.9134
Prevalence : 0.5012
Detection Rate : 0.4555
Detection Prevalence : 0.4722
Balanced Accuracy : 0.9376
'Positive' Class : 0
这个精度适合我,但我想检查一下 auc 的指标。我写:
xgb1 <- xgb.train(params = params, data = dtrain, nrounds = 291, watchlist = list(val=dtest,train=dtrain), print_every_n = 10,
early_stop_round = 10, maximize = F , eval_metric = "auc")
但在那之后我不知道如何对 AUC 指标进行预测。我需要你的帮助,因为这是我第一次使用 XGBoost。谢谢。
UPD:据我所知,在 auc 指标之后我需要一个系数来削减类别。现在我在 0,5 处切断
最佳答案
您可以通过以下方式查看训练数据集的训练模型的 AUC 值
> max(xgb1$evaluation_log$train_auc)
您还可以使用 pROC 包计算您对测试集的预测,如下所示
> library(pROC)
> roc_test <- roc( test_label_vec, predictions_for_test, algorithm = 2)
用你的参数编写的代码是
> roc_test <- roc(ts_label, xgbpred, algorithm = 2)
> plot(roc_test )
> auc(roc_test )
如果你想为你的训练集计算 AUC 并绘制 ROC 曲线,你可以使用以下方法
> roc_training <- roc(train_output_vec, train_predictions, algorithm = 2)
> plot(roc_training )
> auc(roc_training)
ROC曲线和AUC不需要考虑截止点。正在绘制 ROC 并计算 AUC,对预测分数进行排序并查看在预测集中找到的目标事件的百分比。因此,它正在检查如果您移动截止点可以找到多少百分比的目标事件。截止点的决定与成本或算法的应用有关。您可以搜索 cutoff 以获得更多相关信息。
关于r - XGBoost 上的 AUC 指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45834111/
在 SQL 中计算 AUC 的最佳方法是什么? 这是我得到的(假设表 T(label, confid) 和 label=0,1): SELECT sum(cumneg * label) * 1e0 /
我正在训练用于图像分类的CNN。由于我的数据集有限,我正在使用转移学习。基本上,我使用的是Google在其再培训示例(https://www.tensorflow.org/tutorials/imag
我正在 sci-kit learn 中构建 MLPClassifier 模型。我使用 gridSearchCV 和 roc_auc 对模型进行评分。训练和考试的平均成绩在 0.76 左右,还不错。 c
我使用我的测试集作为验证集。我使用了与 How to compute Receiving Operating Characteristic (ROC) and AUC in keras? 类似的方法
我分别从 sklearn 的 RandomForestClassifier 和 roc_curve、auc 方法收到不同的 ROC-AUC 分数。 以下代码让我获得了 0.878 的 ROC-AUC(
如何获得具有 fpr 和 tpr 的 AUC 值? Fpr 和 tpr 只是从这些公式中获得的 2 个浮点数: my_fpr = fp / (fp + tn) my_tpr = tp / (tp +
我有一个分类问题,我想在 sklearn 中使用 cross_validate 获取 roc_auc 值。我的代码如下。 from sklearn import datasets iris = dat
我有一个分类问题,我想在 sklearn 中使用 cross_validate 获取 roc_auc 值。我的代码如下。 from sklearn import datasets iris = dat
在 scikit learn 中,您可以使用以下方法计算二元分类器的曲线下面积 roc_auc_score( Y, clf.predict_proba(X)[:,1] ) 我只对误报率小于 0.1 的
我正在尝试为我的 SVM 找到参数,这些参数会给我最好的 AUC。但是我在 sklearn 中找不到 AUC 的任何评分函数。有人有想法吗?这是我的代码: parameters = {"C":
这是一个代表 library(caret) library(dplyr) set.seed(88, sample.kind = "Rounding") mtcars % mutate(am = a
对于二元分类问题,我有一个略微不平衡的数据集,正负比为 0.6。 我最近从这个答案中了解到了 auc 指标:https://stats.stackexchange.com/a/132832/12822
我有一个 Spark 数据框,如下所示: predictions.show(5) +------+----+------+-----------+ | user|item|rating| predi
我正在研究一个分类问题,其评估指标为 ROC AUC。到目前为止,我已经尝试使用具有不同参数的 xgb 。这是我用来采样数据的函数。并且可以找到相关笔记本here (google colab) def
我对 python 中的 scikit-learn 中如何生成阈值感到困惑。对于以下示例,生成了四个阈值,当我将 pred 中的第三个值更改为 0.6 时,阈值数量降至 3。任何人都可以解释为什么会这
假设我有一个如下所示的数据集: word label_numeric 0 active 0 1 adventurous 0 2 aggressive 0 3 aggressi
我有一个分类问题,需要根据给定的数据预测 (0,1) 类。基本上我有一个包含超过 300 个特征(包括预测目标值)和超过 2000 行(样本)的数据集。我应用了不同的分类器,如下所示: 1. Dec
我的目标是找到预测模型来确定是否偿还贷款。我的来源是一个 CSV 文件,其中包含贷款特征以及是否已偿还。我使用 ROC 曲线和 AUC 评估模型的性能 df = pd.read_csv(your_pa
我想知道为什么我们的目标是在最大化准确率时最大化 AUC? 我认为,除了最大化准确性的主要目标之外,AUC 也会自动变大。 最佳答案 我想我们使用 AUC 是因为它解释了我们的方法能够在多大程度上独立
我正在尝试在非常不平衡的数据集上使用 LightGBM 构建分类器。不平衡的比例为 97:3,即: Class 0 0.970691 1 0.029309 我使用的参数和训练代码如下所示。
我是一名优秀的程序员,十分优秀!