def load_data(path, dense=False):
"""Load data from a CSV or libsvm format file.
Args:
path (str): A path to the CSV or libsvm format file containing data.
dense (boolean): An optional variable indicating if the return matrix
should be dense. By default, it is false.
"""
with open(path, 'r') as f:
line = f.readline().strip()
if ':' in line:
X, y = load_svmlight_file(path)
X = X.astype(np.float32)
if dense:
X = X.todense()
elif ',' in line:
X = np.loadtxt(path, delimiter=',',
skiprows=0 if is_number(line.split(',')[0]) else 1)
y = X[:, 0]
X = X[:, 1:]
else:
raise NotImplementedError, "Neither CSV nor LibSVM formatted file."
return X, y
评论列表
文章目录