Python sklearn.datasets.fetch_olivetti_faces() Examples

The following are 2 code examples for showing how to use sklearn.datasets.fetch_olivetti_faces(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module sklearn.datasets , or try the search function .

Example 1
Project: optuna   Author: optuna   File:    License: MIT License 6 votes vote down vote up
def load_data():
    rng = np.random.RandomState(0)
    dataset = fetch_olivetti_faces(shuffle=True, random_state=rng)
    faces = dataset.images
    target =
    classes = np.unique(target)

    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 
Example 2
Project: ml_code   Author: zlxy9892   File:    License: Apache License 2.0 5 votes vote down vote up
def getImgAsMat(index):
    ds = datasets.fetch_olivetti_faces()
    return np.mat(ds.images[index])