@classmethod
def load_libsvm(cls, f):
    """Create a dataset by reading a sparse LIBSVM/SVMlight format file
        (with labels only)."""
    nFeat = 0
    for line in f:
        n = int(line.split()[-1].split(':')[0])
        if n > nFeat:
            nFeat = n
    f.seek(0)
    labels = []
    features = []
    for line in f:
        if not line:
            break
        line = line.split()
        label = int(line[0])
        feat = []
        nextidx = 1
        for r in line[1:]:
            idx, val = r.split(':')
            idx = int(idx)
            for _ in range(nextidx, idx):
                feat.append(0.0)
            feat.append(float(val))
            nextidx = idx + 1
        for _ in range(nextidx, nFeat + 1):
            feat.append(0.0)
        features.append(feat[:])
        labels.append([label])
    DS = cls(features, labels)
    return DS
