@@ -0,0 +1,2074 @@
+#!/usr/bin/python3%0A%0A%22%22%22An example of the use of non-linear kernel PLS regression on the output of%0Aa function z(x) = 4.26(exp (%E2%88%92x) %E2%88%92 4 exp (%E2%88%922x) + 3 exp (%E2%88%923x))%0A%0AReproduces figure 3 from %22Overview and Recent Advances in Partial Least%0ASquares%22 Roman Rosipal and Nicole Kr%C3%A4mer SLSFS 2005, LNCS 3940, pp. 34%E2%80%9351,%0A2006. %22%22%22%0A%0Aimport math%0Aimport random%0A%0Aimport numpy as np%0Aimport matplotlib.pyplot as plt%0A%0Aimport sys%0Asys.path.append(%22../%22)%0A%0Afrom regressions import kernel_pls, kernels%0A%0A%0Adef z(x):%0A    return 4.26 * (np.exp(-x) - 4 * np.exp(-2.0*x) + 3 * np.exp(-3.0*x))%0A%0A# Define the kernel%0A%0Akern = kernels.make_gaussian_kernel(width=1.8)%0A%0A# Create sample data%0A%0Ax_values = np.linspace(0.0, 3.5, 100).reshape((100, 1))%0A%0Az_pure = z(x_values)%0Az_pure -= z_pure.mean(0)  # Ensure z_pure is centered%0A%0Anoise = np.random.normal(loc=0.0, scale=0.2, size=100).reshape((100, 1))%0Az_noisy = z_pure + noise%0Az_noisy -= z_noisy.mean(0)  # Ensure z_noisy is centered%0A%0A# Perform Kernel PLS%0A%0Akpls_1 = kernel_pls.Kernel_PLS(X=x_values,%0A                               Y=z_noisy,%0A                               g=1,%0A                               X_kernel=kern)%0A%0Akpls_1_results = kpls_1.prediction(x_values)%0A%0Akpls_4 = kernel_pls.Kernel_PLS(X=x_values,%0A                               Y=z_noisy,%0A                               g=4,%0A                               X_kernel=kern)%0A%0Akpls_4_results = kpls_4.prediction(x_values)%0A%0Akpls_8 = kernel_pls.Kernel_PLS(X=x_values,%0A                               Y=z_noisy,%0A                               g=8,%0A                               X_kernel=kern)%0A%0Akpls_8_results = kpls_8.prediction(x_values)%0A%0A# Plot the results of the above calculations%0A%0Afig = plt.figure('An example of Kernel PLS regression')%0A%0Aplt.title('An example of Kernel PLS regression')%0Aplt.plot(x_values, z_pure, 'k-', label='$z(.)$')%0Aplt.plot(x_values, z_noisy, 'k+', label='$z(.)$ with noise')%0Aplt.plot(x_values, kpls_1_results, 'k--', label='KPLS 1C')%0Aplt.plot(x_values, kpls_4_results, 'k:', label='KPLS 4C')%0Aplt.plot(x_values, kpls_8_results, 'k-.', label='KPLS 8C')%0Aplt.legend(loc=4)%0A%0Aplt.show()%0A

Add another kernel PLS example