##### How to modify and get the same picture
 How to modify and get the same picture vokoyo Silly Frenchman Posts: 27 Threads: 16 Joined: Apr 2018 Reputation: Jun-01-2019, 01:17 AM (This post was last modified: Jun-01-2019, 01:18 AM by vokoyo.) May I know how to modify my Python programming thus I can get the same picture as refer to the attached file ```from scipy import exp from scipy.linalg import eigh from scipy.spatial.distance import pdist, squareform from sklearn.datasets import make_moons from sklearn.decomposition import PCA import matplotlib.pyplot as plt import numpy as np import pandas as pd def rbf_kernel_pca(X, gamma, n_components): """ RBF kernel PCA implementation. Parameters ------------ X: {NumPy ndarray}, shape = [n_samples, n_features] gamma: float Tuning parameter of the RBF kernel n_components: int Number of principal components to return Returns ------------ X_pc: {NumPy ndarray}, shape = [n_samples, k_features] Projected dataset """ sq_dists = pdist(X, 'sqeuclidean') # Convert pairwise distances into a square matrix. mat_sq_dists = squareform(sq_dists) # Compute the symmetric kernel matrix. K = exp(-gamma * mat_sq_dists) # Center the kernel matrix. N = K.shape[0] one_n = np.ones((N,N)) / N K = K - one_n.dot(K) - K.dot(one_n) + one_n.dot(K).dot(one_n) # Obtaining eigenpairs from the centered kernel matrix # numpy.eigh returns them in sorted order eigvals, eigvecs = eigh(K) # Collect the top k eigenvectors (projected samples) X_pc = np.column_stack((eigvecs[:, -i] for i in range(1, n_components + 1))) return X_pc X, y = make_moons(n_samples=100, random_state=123) from matplotlib.ticker import FormatStrFormatter fig, ax = plt.subplots(nrows=3, ncols=1, figsize=(8,5)) X_kpca = rbf_kernel_pca(X, gamma=0.1, n_components=2) ax[0].scatter(X_kpca[y==0, 0], X_kpca[y==0, 1], color='red', marker='^', alpha=0.5) ax[0].scatter(X_kpca[y==1, 0], X_kpca[y==1, 1], color='blue', marker='o', alpha=0.5) ax[0].set_xlim([-0.6, 0.6]) ax[0].set_ylim([-0.3, 0.3]) ax[0].set_xlabel('PC1') ax[0].set_ylabel('PC2') plt.title('gamma=0.1') X_kpca = rbf_kernel_pca(X, gamma=15, n_components=2) ax[1].scatter(X_kpca[y==0, 0], X_kpca[y==0, 1], color='red', marker='^', alpha=0.5) ax[1].scatter(X_kpca[y==1, 0], X_kpca[y==1, 1], color='blue', marker='o', alpha=0.5) ax[1].set_xlim([-0.4, 0.4]) ax[1].set_ylim([-0.3, 0.3]) ax[1].set_xlabel('PC1') ax[1].set_ylabel('PC2') plt.title('gamma=15') X_kpca = rbf_kernel_pca(X, gamma=150, n_components=2) ax[2].scatter(X_kpca[y==0, 0], X_kpca[y==0, 1], color='red', marker='^', alpha=0.5) ax[2].scatter(X_kpca[y==1, 0], X_kpca[y==1, 1], color='blue', marker='o', alpha=0.5) ax[2].set_xlim([-0.2, 0.2]) ax[2].set_ylim([-0.3, 0.3]) ax[2].set_xlabel('PC1') ax[2].set_ylabel('PC2') plt.title('gamma=150') plt.tight_layout() plt.show()``` Please see the image file - Please help me on this case Reply dataman Unladen Swallow Posts: 2 Threads: 0 Joined: Jul 2019 Reputation: Jul-07-2019, 11:37 AM (This post was last modified: Jul-07-2019, 09:53 PM by Yoriz.) hi i can help u Reply

 Possibly Related Threads… Thread Author Replies Views Last Post How to find axiom of this picture DerbyHarrington 2 773 Mar-15-2020, 12:02 PM Last Post: DerbyHarrington Why there is no any input of the picture? Tony 2 1,444 May-19-2018, 07:20 AM Last Post: Tony

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020