标签: roc

如何在R中绘制Logistic回归(LASSO)的ROC曲线?

我将逻辑回归模型拟合到R中的训练数据集,更具体地说是具有L1惩罚的LASSO回归.我用了这个glmnet包.模型的代码如下所示.

t1 <- Sys.time()
glmnet_classifier <- cv.glmnet(x = dtm_train_tfidf,
                           y = tweets_train[['sentiment']], 
                           family = 'binomial', 
                           # L1 penalty
                           alpha = 1,
                           # interested in the area under ROC curve
                           type.measure = "auc",
                           # 5-fold cross-validation
                           nfolds = 5,
                           # high value is less accurate, but has faster training
                           thresh = 1e-3,
                           # again lower number of iterations for faster training
                           maxit = 1e3)
print(difftime(Sys.time(), t1, units = 'mins'))

preds <- predict(glmnet_classifier, dtm_test_tfidf, type = 'response')[ ,1]
Run Code Online (Sandbox Code Playgroud)

现在我想绘制ROC曲线.但是,我无法弄清楚如何准确地绘制它.

当我 …

r glmnet roc logistic-regression

0
推荐指数
1
解决办法
3761
查看次数

train() 中的 ROC 指标,插入符号包

df在训练和测试dataframes分裂。训练数据帧分为训练数据帧和测试数据帧。因变量Y是二进制(因子),值为 0 和 1。我试图用这个代码(神经网络,插入符号包)预测概率:

library(caret)

model_nn <- train(
  Y ~ ., training,
  method = "nnet",
  metric="ROC",
  trControl = trainControl(
    method = "cv", number = 10,
    verboseIter = TRUE,
    classProbs=TRUE
  )
)

model_nn_v2 <- model_nn
nnprediction <- predict(model_nn, testing, type="prob")
cmnn <-confusionMatrix(nnprediction,testing$Y)
print(cmnn) # The confusion matrix is to assess/compare the model
Run Code Online (Sandbox Code Playgroud)

但是,它给了我这个错误:

    Error: At least one of the class levels is not a valid R variable name; 
This will cause errors when class probabilities are generated …
Run Code Online (Sandbox Code Playgroud)

r machine-learning neural-network roc r-caret

0
推荐指数
1
解决办法
3341
查看次数

了解 ROC 曲线

import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc , roc_auc_score
import numpy as np

correct_classification = np.array([0,1])
predicted_classification = np.array([1,1])

false_positive_rate, true_positive_rate, tresholds = roc_curve(correct_classification, predicted_classification)

print(false_positive_rate)
print(true_positive_rate)
Run Code Online (Sandbox Code Playgroud)

来自https://en.wikipedia.org/wiki/Sensitivity_and_specificity

True positive: Sick people correctly identified as sick 
False positive: Healthy people incorrectly identified as sick 
True negative: Healthy people correctly identified as healthy 
False negative: Sick people incorrectly identified as healthy
Run Code Online (Sandbox Code Playgroud)

我使用这些值 0:生病,1:健康

来自https://en.wikipedia.org/wiki/False_positive_rate

闪阳性率 = 假阳性 / (假阳性 + 真阴性)

误报数量 : 0 真阴性数量 …

false-positive roc scikit-learn

0
推荐指数
1
解决办法
1451
查看次数

如何在 Keras 中绘制 MLP 模型的训练损失和准确度曲线?

我使用Keras模拟神经网络,我试图用一个图来评估它accval_acc。我在以下代码行中有 3 个错误:

  1. print(history.keys())错误是function' object has not attribute 'keys'
  2. y_pred = classifier.predict(X_test)错误是name 'classifier' is not defined
  3. plt.plot(history.history['acc'])错误是 'History' object is not subscriptable

我也在尝试绘制 ROC 曲线,我该怎么做?

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import keras
from keras.models import Sequential
from keras.layers import Dense
from sklearn import cross_validation
from matplotlib import pyplot
from keras.utils import plot_model

dataset = pd.read_csv('Data_BP.csv')
X = dataset.iloc[:, 0:11].values
y = …
Run Code Online (Sandbox Code Playgroud)

neural-network roc scikit-learn keras tensorflow

0
推荐指数
1
解决办法
1万
查看次数

如果False Positve和True Negative的总和为零,如何计算误报率(FPR)?

我正在进行性能测量并尝试绘制ROC曲线,但要绘制ROC曲线我需要TPR和FPR.

据我们所知,

误报率(FPR)= FP /(FP + TN)

我有TN和FP的值都等于0,那么如何计算这种情况下的FPR并输入ROC曲线?

machine-learning false-positive roc

-1
推荐指数
1
解决办法
2196
查看次数

ValueError:尝试计算 ROC 曲线时输入形状错误 (2, 256, 3)

首先,我是Python新手。尝试构建 ROC 曲线时,我在此代码行上收到错误:

fpr_keras, tpr_keras, thresholds_keras = roc_curve(Y_test.argmax(axis=1), decoded_imgs.argmax(axis=1))
Run Code Online (Sandbox Code Playgroud)

错误:

ValueError:输入形状错误(2、256、3)

当我在重塑后尝试塑造时,出现第二个错误:

类型错误:“元组”对象不可调用

我点击了这个链接,但我不明白我应该做什么,我正在解决这个问题。有人可以编辑我的代码吗?这就是我想做的:link2

import keras
import numpy as np
from keras.datasets import mnist
from get_dataset import get_dataset
from stack import keras_model

X_train, X_test, Y_train, Y_test = get_dataset()

from keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D, Dense
from keras.models import Model

input_img = Input(shape=(256, 256, 3))

x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(64, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning roc scikit-learn keras

-1
推荐指数
1
解决办法
1134
查看次数