python - Create a Numpy Array from particular text format -
i have text file containing training vectors
<vector 1-dimension 1> <vector 1 - dimension 2> .... <vector 1 - dimension n> ............. ............. ............. ............. ............. <vector m - dimension 1> <vector m - dimension 2> .... <vector m - dimension n>
another text file mentions class memberships of corresponding vectors
vector1-class vector2-class ............. vector n - class
now, need convert these numpy arrays x , y, can give them input scikit learn linear svm function ; example in python code,
from sklearn import svm x = [[1,1], [1,-1], [-1,1], [-1,-1]] y = [0, 1, 2, 3] clf = svm.svc() clf.fit(x, y)
how can achieve this?
after bit of research, have used
x = np.genfromtxt("x.txt",delimiter=" ") y = np.genfromtxt("y.txt",delimiter=" ")
to achieve same.
is there better way achieve same? if textfile written in sparse format, is, if nonzero elements mentioned ordered pairs, how can achieve same result?
Comments
Post a Comment