def test_dump_qid(self): tmpfile = "/tmp/tmp_dump.txt" try: # loads from file Xs, y, q = load_svmlight_file(qid_datafile, query_id=True) # dumps to file dump_svmlight_file(Xs, y, tmpfile, query_id=list(q), zero_based=False) # loads them as CSR MATRIX with scikit-learn X2, y2, q2 = sk_load_svmlight_file(tmpfile, query_id=True) X3 = np.ndarray(shape=X2.shape, dtype=X2.dtype) X2.toarray(out=X3) # check assertions assert_array_almost_equal(Xs, X3) assert_array_almost_equal(y, y2) assert_array_equal(q, q2) finally: if os.path.exists(tmpfile): os.remove(tmpfile)
def test_dump(): try: Xs, y = load_svmlight_file(datafile) tmpfile = "tmp_dump.txt" dump_svmlight_file(Xs, y, tmpfile, zero_based=False) X2, y2 = sk_load_svmlight_file(tmpfile) assert_array_equal(Xs.toarray(), X2.toarray()) assert_array_equal(y, y2) finally: os.remove(tmpfile)
def test_dump(): Xs, y = load_svmlight_file(datafile) Xd = Xs.toarray() for X in (Xs, Xd): f = StringIO() dump_svmlight_file(X, y, f, zero_based=False) f.seek(0) X2, y2 = sk_load_svmlight_file(f) assert_array_equal(Xd, X2.toarray()) assert_array_equal(y, y2)
def test_dump(self): tmpfile = "tmp_dump.txt" try: # loads from file Xs, y = load_svmlight_file(datafile) # dumps to file dump_svmlight_file(Xs, y, tmpfile, zero_based=False) # loads them as CSR MATRIX X2, y2 = sk_load_svmlight_file(tmpfile) X3 = np.ndarray(shape=X2.shape, dtype=X2.dtype) X2.toarray(out=X3) # check assertions assert_array_almost_equal(Xs, X3) assert_array_almost_equal(y, y2) finally: if os.path.exists(tmpfile): os.remove(tmpfile)