Python源码示例:sklearn.datasets.fetch_olivetti_faces()

示例1
def load_data():
    rng = np.random.RandomState(0)
    dataset = fetch_olivetti_faces(shuffle=True, random_state=rng)
    faces = dataset.images
    target = dataset.target
    classes = np.unique(target)
    classes.sort()

    ref_index = np.argmax(target == classes[:, None], axis=1)
    valid_index = np.delete(np.arange(len(faces)), ref_index)

    x_ref = faces[ref_index]
    y_ref = target[ref_index]
    x_valid = faces[valid_index]
    y_valid = target[valid_index]
    return x_ref, x_valid, y_ref, y_valid 
示例2
def getImgAsMat(index):
    ds = datasets.fetch_olivetti_faces()
    return np.mat(ds.images[index])