I am running a bunch of experiments where the pre-processing changes on nearly every iteration. Once I have the data in a format, I need to run a classifier from scikits (liblinear). I can get the data into svm light format. I understand there is a module to convert that to the scikits standard. The issues is that I dont want to write a file to disk. I have 48 gigs of memory and would much rather make the conversion in memory.
Below is an example where I take the svm light format, write ito to a stringio object and sic the svm light loader on it. Unfortunately the loader refuses to be siced (it works other wise). Any suggestions? I am running over a 1000 different pre-processing pipelines, and i cant keep writing to the disk.
sample svm light data is at: http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary/a1a
My code
import numpy as np
from sklearn.datasets import svmlight_format
import cStringIO
bufFile = cStringIO.StringIO()
with open('C:/Users/theDesktop/Desktop/sampleData.txt') as a:
p = a.readlines()
a.close()
bufFile.writelines(p)
X_train, y_train = svmlight_format.load_svmlight_file(bufFile)
My error:
Traceback (most recent call last):
File "C:\Users\theDesktop\Desktop\module1.py",
line 25, in <module> X_train, y_train=svmlight_format.load_svmlight_file(bufFile)
File "C:\Python27\lib\site-packages\sklearn\datasets\svmlight_format.py",
line 97, in load_svmlight_file zero_based))
File "C:\Python27\lib\site-packages\sklearn\datasets\svmlight_format.py",
line 177, in load_svmlight_files for _, indices, _, _ in r):
File "C:\Python27\lib\site-packages\sklearn\datasets\svmlight_format.py",
line 177, in <genexpr> for _, indices, _, _ in r):
File "C:\Python27\lib\site-packages\numpy\core\fromnumeric.py",
line 1895, in amin return amin(axis, out)
ValueError: zero-size array to minimum.reduce without identity