Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 稀疏(csr)特征矩阵上的分层KFold_Python_Machine Learning_Scikit Learn_Sparse Matrix_Cross Validation - Fatal编程技术网

Python 稀疏(csr)特征矩阵上的分层KFold

Python 稀疏(csr)特征矩阵上的分层KFold,python,machine-learning,scikit-learn,sparse-matrix,cross-validation,Python,Machine Learning,Scikit Learn,Sparse Matrix,Cross Validation,我有一个大的稀疏矩阵(9500012000),包含了我模型的特征。我想使用python中的Sklearn.cross_验证模块进行分层K折叠交叉验证。然而,我还没有在python中找到索引稀疏矩阵的方法 我是否可以在稀疏特征矩阵上执行分层折叠?试试以下方法: # First make sure sparse matrix is to_csr X_sparse = x.tocsr() y= output X_train = {} Y_train = {} skf = StratifiedKFol

我有一个大的稀疏矩阵(9500012000),包含了我模型的特征。我想使用python中的Sklearn.cross_验证模块进行分层K折叠交叉验证。然而,我还没有在python中找到索引稀疏矩阵的方法

我是否可以在稀疏特征矩阵上执行分层折叠?

试试以下方法:

# First make sure sparse matrix is to_csr
X_sparse = x.tocsr()
y= output
X_train = {}
Y_train = {}

skf = StratifiedKFold(5, shuffle=True, random_state=12345)
i=0
for train_index, test_index in skf.split(X,y):
    print("TRAIN:", train_index, "TEST:", test_index)
    X_train[i], X_test[i] = X[train_index], X[test_index]
    y_train[i], y_test[i] = y[train_index], y[test_index]
    i +=1

很明显,你甚至没有试过。Scikit learn CV在稀疏矩阵上运行良好,因为csr_矩阵是Scikit-learn中的默认数据表示形式。它是否给了您一个错误“整数无法索引”?