text_plain_output_3.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png image_output_1.png
from sklearn.manifold import Isomap
fig = plt.figure(figsize=(25, 8))
plt.suptitle(str_data_inf + ' n_samples=' + str(len(X)), fontsize=20)
c = 0
for n_neighbors in [5, 10]:
    reducer = Isomap(n_components=2, n_neighbors=n_neighbors)
    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', n_neighbors)
        continue
    t1 = time.time()
    print('Isomap n_neighbors %s: %.2g sec' % (n_neighbors, t1 - t0))
    c += 1
    fig.add_subplot(1, 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('Isomap n_neighbors' + str(n_neighbors), fontsize=20)
    if c == 1:
        plt.setp(ax.get_legend().get_texts(), fontsize=12)
        plt.setp(ax.get_legend().get_title(), fontsize=12)
        plt.legend(bbox_to_anchor=(1.15, 1.0), loc='upper right')
    else:
        plt.legend('')
plt.show()