- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要的是:
为此,我的方法是使用 this非常好的教程:
根据他的想法和方法,我只是改变了我获取原始数据的方式,我得到的是这样的:
df = pd.read_csv(
filepath_or_buffer='https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data',
header=None,
sep=',')
df.columns=['sepal_len', 'sepal_wid', 'petal_len', 'petal_wid', 'class']
df.dropna(how="all", inplace=True) # drops the empty line at file-end
df.tail()
# split data table into data X and class labels y
X = df.iloc[:,0:4].values
Y = df.iloc[:,4].values
他们我只是运行代码。如果我尝试运行 accuracy
或
等指标balanced_accuracy
一切正常(即使有许多其他指标)。我的问题是,当我尝试使用指标 roc_auc
运行时,出现错误:
"ValueError: Only one class present in y_true. ROC AUC score is not defined in that case."
这个错误已经讨论过here1 , here2 , here3 , 和 here4 .但是,我无法使用他们提供的任何“解决方案”/解决方法来解决我的问题。
我的全部代码是:
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import pandas as pd
import numpy as np
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode
from sklearn.preprocessing import StandardScaler
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'qt')
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
df = pd.read_csv(
filepath_or_buffer='https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data',
header=None,
sep=',')
df.columns=['sepal_len', 'sepal_wid', 'petal_len', 'petal_wid', 'class']
df.dropna(how="all", inplace=True) # drops the empty line at file-end
df.tail()
# split data table into data X and class labels y
X = df.iloc[:,0:4].values
Y = df.iloc[:,4].values
#print(X)
#print(Y)
seed = 7
# prepare models
models = []
models.append(('LR', LogisticRegression()))
# evaluate each model in turn
results = []
names = []
scoring = 'roc_auc'
for name, model in models:
kfold = model_selection.KFold(n_splits=5, random_state=seed)
cv_results = model_selection.cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
results.append(cv_results)
names.append(name)
msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
print(msg)
# boxplot algorithm comparison
fig = plt.figure()
fig.suptitle('Algorithm Comparison')
ax = fig.add_subplot(111)
plt.boxplot(results)
ax.set_xticklabels(names)
plt.show()
最佳答案
鸢尾花数据集通常根据类别排序。因此,当您在不进行洗牌的情况下进行拆分时,测试数据集可能只会得到一个类。
一个简单的解决方案是使用 shuffle
参数。
kfold = model_selection.KFold(n_splits=10, shuffle=True, random_state=seed)
即便如此,roc_auc
也不直接支持多类格式(iris - 数据集具有三个类)。
通过this链接以了解有关如何将 roc_auc
用于多类情况的更多信息。
关于python - 将 ROC AUC 分数与 Logistic 回归和 Iris 数据集结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55944240/
我有一个包含 100 个样本的数据集,每个样本都有 195 个突变,具有相应的已知临床意义(“RealClass”)和根据某些预测工具的预测值(“PredictionValues”) 为了演示,这是一
从下面的代码中,看起来使用 keras 和 scikit 评估 roc 实际上有所不同。有人知道解释吗? import tensorflow as tf from keras.layers impor
我很难理解 multiclass.roc 参数应该是什么样子。这是我的数据快照: > head(testing.logist$cut.rank) [1] 3 3 3 3 1 3 Levels: 1 2
我已经使用 ROCR 包绘制了 2 类问题的 ROC 曲线。根据我的理解,至少对于较小的数据集,曲线应该看起来像阶跃变化图。我的输入实际上很小,但我得到的曲线基本上看起来是直线。是因为 PROC 适合
我正在尝试使用 rpart 在插入符号中最大限度地提高模型选择的灵敏度。为此,我尝试复制此处给出的方法(向下滚动到使用用户定义函数 FourStat 的示例)caret's github page #
我正在尝试使用插入符包生成随机森林模型,使用 ROC 曲线下的面积作为训练指标,但我收到以下警告: Warning message: In train.default(x = TrainData, y
我在 R 平台中使用 randomForest 包进行分类任务。 rf_object<-randomForest(data_matrix, label_factor, cutoff=c(k,1-k))
我正在构建两个不同的分类器来预测二进制结果。然后我想通过使用 ROC 曲线及其下面积 (AUC) 来比较两个模型的结果。 我将数据集分为训练集和测试集。在训练集上,我执行一种形式的交叉验证。从交叉验证
我最近在为我的项目使用 sklearn 时遇到困难。我想构建一个分类器并将我的数据分为六组。总样本量为 88 然后我将数据分成 train(66) 和 test(22)我完全按照 sklearn 文档
我正在进行不同的文本分类实验。现在我需要计算每个任务的 AUC-ROC。对于二进制分类,我已经使用以下代码使其工作: scaler = StandardScaler(with_mean=False)
我正在尝试应用 sklearn 的想法 ROC extension to multiclass到我的数据集。我的每类 ROC 曲线看起来都找到了一条直线,取消显示曲线波动的 sklearn 示例。 我
这是一个代表 library(caret) library(dplyr) set.seed(88, sample.kind = "Rounding") mtcars % mutate(am = a
我有以下概念问题,我无法理解。 以下是调查数据示例,其中我有一个时间列,指示某人需要多长时间才能回答某个问题。 现在,我感兴趣的是清洁量将如何根据此阈值发生变化,即如果我增加阈值会发生什么,如果我降低
如何为使用视频的对象检测应用绘制每个窗口的误报率与未命中率(或误报概率)和 ROC(接收器操作曲线)的图表?如何确定误报和命中的数量?一个例子是很有用。 最佳答案 它很简单。将所有真正 (H0) 值存
我正在尝试绘制随机森林分类的 ROC 曲线。绘图有效,但我认为我绘制了错误的数据,因为生成的绘图只有一个点(准确性)。 这是我使用的代码: set.seed(55) data.controls <
我有如下两个模型: library(mlbench) data(Sonar) library(caret) set.seed(998) my_data <- Sonar fitControl <-
我很难将 ROC 的示例命令转换为我的数据集。这是用于 pROC 包 这是使用数据(aSAH)的例子 roc(aSAH$outcome, aSAH$s100b) roc(outcome ~ s100b
我试图在多类 knn 模型和数据集上运行一些 ROC 分析 到目前为止,我有 kNN 模型的这段代码。它运作良好。X_train_new是一个包含 131 个数值变量(列)和 7210 个观测值的数据
是否可以仅通过查看其 ROC 曲线来了解分类器是否过度拟合?我看到如果它的 AUC 太高(例如 98%)可能会过度拟合,但这也可能意味着分类器非常好。有没有办法区分这两种情况? 最佳答案 简短的回答:
在运行逻辑回归后,我使用以下代码绘制 ROC 曲线。 fit1 <- glm(formula=GB160M3~Behvscore, data=eflscr,family="binomial", na.
我是一名优秀的程序员,十分优秀!