【发布时间】:2015-09-26 18:12:09
【问题描述】:
我有一个稀疏矩阵 G,其值(非 nan 值)需要拆分为测试/训练集。 sklearn 中的 test_train_split 函数在行上拆分,但我希望它在实际索引上拆分。这大概就是我想要做的事情
1. test, train = split non-nan values in G (80/20-train/test)
2. test_and_nan = combine test and nan sets
3. G2 = G.copy()
4. G2[ test_and_nan ] = 0 // initialize to 0 before imputing
5.
6. do until norm(G2, frobenius) doesnt change much from last iteration
7. S,C = nmf(G2)
8. // use nmf decomposition to impute test_and_nan values
9. G2[ test_and_nan ] = (S*C)[ test_and_nan ]
10.
11. compute rmse( G[test] - G2[test] )
我想使用布尔掩码来选择索引,但我不知道该怎么做。任何帮助将不胜感激。
【问题讨论】:
标签: python numpy pandas scikit-learn