Created
July 9, 2012 21:13
-
-
Save ibayer/3078964 to your computer and use it in GitHub Desktop.
Testing how sparse datasets that are only available as RData file could be converted to the mldata.org hdf5 format. This is not working as the hdf5 specification stated on mldata.org is not recognized from the there parser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.io.mmio import mminfo,mmread,mmwrite | |
import numpy as np | |
import h5py | |
import os | |
os.chdir('/home/mane/workspace/benchmark/') | |
print mminfo('InternetAd') | |
X = mmread('InternetAd.mtx') | |
y = np.loadtxt('InternetAd.target', skiprows=0) | |
f = h5py.File('InternetAd.h5', 'w') | |
# HDF5 attributes on the root level | |
f.attrs['mldata'] = 0 | |
f.attrs['name'] = 'InternetAd' | |
f.attrs['comment'] = 'Internet-Ad [Kushmerick, 1999]: document classification problem with \ | |
mostly binary features.' | |
#HDF5 group 'data_descr' | |
f.create_group('/data_descr') | |
f['/data_descr/ordering'] = np.array(['label', 'data']) | |
#HDF5 group 'data' | |
f.create_group('/data') | |
f['/data/data'] = X.data | |
f['/data/data_indices'] = X.tocsc().indices | |
f['/data/data_indptr'] = X.tocsc().indptr | |
f['/data/label'] = y | |
f.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load('InternetAd.RData') | |
file = file.path(getwd(), 'InternetAd.mtx') | |
library(Matrix) | |
writeMM(InternetAd$x, file=file) | |
file = file.path(getwd(), 'InternetAd.target') | |
write(InternetAd$y, file=file, ncolumns=1) | |
load('NewsGroup.RData') | |
file = file.path(getwd(), 'NewGroup.mtx') | |
library(Matrix) | |
writeMM(NewsGroup$x, file=file) | |
file = file.path(getwd(), 'NewsGroup.target') | |
write(NewsGroup$y, file=file, ncolumns=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment