python - SKLearn Kernel PCA "Precomputed" argument -


i trying perform kernel pca using scikit-learn, using kernel not in implementation (and custom input format recognized kernel). easiest if compute kernel ahead of time, save it, , use in kernel pca.

the precomputed argument kernelpca imply able want; however, it's not explained in documentation, , can't find examples of being used. in the unit test source code kernelpca in sklearn, code doesn't ever seem precomputed kernel is.

does know how use own precomputed kernel?

the precomputed kernel need use @ fit time gram matrix between samples. i.e. if have n_samples samples denoted x_i, need give fit first parameter matrix g defined g_ij = k(x_i, x_j) i, j between 0 , n_samples - 1.

e.g. linear kernel is

def linear_kernel(x, y):     return x.dot(y.t)  x = np.random.randn(10, 20) gram = linear_kernel(x, x) 

for prediction on x_test need pass

x_test = np.random.randn(5, 20) gram_test = linear_kernel(x_test, x) 

this seen in unit tests, e.g. here


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -