首页 > 解决方案 > 如何在多标签 uskig sklearn 上进行分层测试和训练拆分

问题描述

我正在关注这个链接:

https://datascience.stackexchange.com/questions/45174/how-to-use-sklearn-train-test-split-to-stratify-data-for-multi-label-classificat

我有一个training数据框和相应labels的数据框。这是multi-labelled text classification问题。多编码向量的维数为45

训练数据是形状8000000*5行。

标签示例:

c_0  c_1   c_2  c_3 ..............c_44
 0.   1.   1.    0. .............. 0
 0.   1.   0.    1. .............. 1

我正在使用此代码进行训练和测试拆分:

%%时间

为多标签多类分类执行分层抽样

from skmultilearn.model_selection import IterativeStratification
stratifier = IterativeStratification(n_splits=2, order=45, sample_distribution_per_fold=[0.10, 0.90])
train_indexes, test_indexes = next(stratifier.split(sample_data_df,labels_df))
X_train, y_train = sample_data_df.loc[train_indexes], labels_df.loc[train_indexes]
X_test, y_test = sample_data_df.loc[test_indexes], labels_df.loc[test_indexes]

我不明白什么是n_splits=2order=45代表什么。

它也继续运行而不收敛。

有没有更快的方法将这些数据拆分为训练和测试?

标签: python-3.xpandasscikit-learntrain-test-split

解决方案


推荐阅读