text_plain_output_2.png text_plain_output_1.png image_output_1.png
from sklearn.manifold import LocallyLinearEmbedding
for n_neighbors in [5, 10]:
    print('n_neighbors', n_neighbors)
    fig = plt.figure(figsize=(25, 16))
    plt.suptitle(str_data_inf + ' n_samples=' + str(len(X)), fontsize=20)
    c = 0
    for method in ['standard', 'hessian', 'modified', 'ltsa']:
        if method == 'hessian':
            reducer = LocallyLinearEmbedding(n_components=2, n_neighbors=6, method=method)
        else:
            reducer = LocallyLinearEmbedding(n_components=2, n_neighbors=n_neighbors, method=method)
        t0 = time.time()
        try:
            if isinstance(X, pd.DataFrame):
                r = reducer.fit_transform(X.iloc[:N, :])
            else:
                r = reducer.fit_transform(X[:N, :])
        except Exception as e:
            print(e)
            print('Got Exception', method)
            continue
        t1 = time.time()
        print('LLE %s: %.2g sec' % (method, t1 - t0))
        c += 1
        fig.add_subplot(2, 2, c)
        if isinstance(v4color, pd.Series):
            sns.scatterplot(x=r[:, 0], y=r[:, 1], hue=v4color.iloc[:N], palette=palette1, marker=marker1, alpha=alpha1)
        else:
            sns.scatterplot(x=r[:, 0], y=r[:, 1], hue=v4color[:N], palette=palette1, marker=marker1, alpha=alpha1)
        plt.title('LLE ' + str(method), fontsize=20)
        plt.legend('')
    plt.show()