- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 Sklearn 分层 kfold 拆分,当我尝试使用多类拆分时,我收到错误消息(见下文)。当我尝试使用二进制进行拆分时,它没有问题。
num_classes = len(np.unique(y_train))
y_train_categorical = keras.utils.to_categorical(y_train, num_classes)
kf=StratifiedKFold(n_splits=5, shuffle=True, random_state=999)
# splitting data into different folds
for i, (train_index, val_index) in enumerate(kf.split(x_train, y_train_categorical)):
x_train_kf, x_val_kf = x_train[train_index], x_train[val_index]
y_train_kf, y_val_kf = y_train[train_index], y_train[val_index]
ValueError: Supported target types are: ('binary', 'multiclass'). Got 'multilabel-indicator' instead.
最佳答案
keras.utils.to_categorical
产生一个单热编码的类向量,即 multilabel-indicator
错误信息中提到。 StratifiedKFold
不适用于此类输入;来自 split
方法 docs :
split
(X, y, groups=None)[...]
y : array-like, shape (n_samples,)
The target variable for supervised learning problems. Stratification is done based on the y labels.
即你的y
必须是您的类标签的一维数组。
本质上,您要做的只是颠倒操作顺序:首先拆分(使用您的初始 y_train
),然后转换 to_categorical
之后。
关于python - Sklearn StratifiedKFold : ValueError: Supported target types are: ('binary' , 'multiclass' )。取而代之的是 'multilabel-indicator',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48508036/
我有一个使用 Scikit-Learn API 的 Keras 包装器构建的 Keras 分类器。该神经网络有10个输出节点,训练数据全部采用one-hot编码表示。 根据Tensorflow doc
当我尝试使用metrics.roc_auc_score时,我收到ValueError:不支持多类格式。 import lightgbm as lgb from sklearn import metri
我正在尝试在 Keras 中使用 CNN 执行多类多标签分类。我试图基于 this function 创建一个单独的标签精度函数来自类似的问题 我尝试过的相关代码是: labels = ["dog",
这是我的代码,我尝试计算 ROC 分数,但我遇到了 ValueError 问题:不支持多类格式。我已经在寻找 sci-kit learn 但它没有帮助。最后,我仍然有 ValueError: mult
我试图理解如何使用一对一方法在多类分类场景中解释决策函数值。我创建了一个 2D 样本数据,每个样本包含 4 个类别的 100 个样本,存储在 X 和 y 变量中。这是代码: # 4 Classes -
我已经使用 U-net 一段时间了,并注意到在我的大多数应用程序中,它都会对特定类产生高估。 例如,这是一个灰度图像: 手动分割 3 个类别(病变 [绿色]、组织 [洋红色]、背景 [所有其他]):
我的第一个多类分类。我有值 X 和 Y。Y 有 5 个值 [0,1,2,3,4]。但我得到这个“不支持多类格式”。明白我需要 xgb_params 中的 num_class,但是如果我写 'num_c
我正在尝试为高度不平衡和多类别的数据生成ROC曲线(我知道这不是理想的,这是本论文的审稿人要求的)。SKLEARY在这里有一个选项:https://scikit-learn.org/stable/au
I have 20 different labels and they are [0, 1, 2, ..., 20]. Let's say that I have 5 samples and t
I am trying to generate a ROC curve for data that is highly imbalanced and multiclass (I know thi
如标题所述,多类分类并没有返回我在训练集中定义的正确类,而是返回第一类(预测类),其他类只是它的变体。 示例请求: curl https://api.openai.com/v1/completions
如标题所述,多类分类并没有返回我在训练集中定义的正确类,而是返回第一类(预测类),其他类只是它的变体。 示例请求: curl https://api.openai.com/v1/completions
我已经看到我们可以使用Dense(num_classes, ...)作为输出层,但我也看到Dense((num_classes-1), .. .) 尤其是在谈论二元分类时。您使用哪一个以及为什么? 最
我正在使用组合在一起的推文训练和测试数据集。 (combi = train.append(测试,ignore_index=True)。 训练 csv 手动标记了情绪:-1、0 和 1(基本上是负面、中
我是 Python 和机器学习的新手。根据我的要求,我正在尝试对我的数据集使用朴素贝叶斯算法。 我能够找出准确度,但试图找出精确度和召回率。但是,它抛出以下错误: ValueError: Target
在泡菜... 我有一个包含 >100,000 个观察值的数据集;数据集的列包括 客户 ID , 供应商 ID , 产品编号 和 CatNMap .这是它的样子: 正如您所看到的,前 3 列(Custo
我有training set和 test set (带标题的 csv 文件),我必须对其中的每个值进行分类。 X 列中有 118.000 个 uniq 值,而 y1 列中只有大约 13000 个,因此
相对简单的问题。查看 xgboost 的目标文档,我看到“multi:softmax”和“multi:softprob”,但它们都是 mutliclass,只会输出一个类。有什么方法可以使用 xgbo
我很难理解 multiclass.roc 参数应该是什么样子。这是我的数据快照: > head(testing.logist$cut.rank) [1] 3 3 3 3 1 3 Levels: 1 2
引用https://dzone.com/articles/machine-learning-with-h2o-hands-on-guide-for-data 我能够按照示例绘制 ROC 和 AUC 曲
我是一名优秀的程序员,十分优秀!