human
I am working on the file "R_lab1_ML_Bay_Regresion/Pract_regression_professor.ipynb".
The first task is:
[3] Since the data have been taken from a real scenario, we do not have any true mathematical model of the process that generated the data. Thus, we will explore different models trying to take the one that fits better the training data.

Assume a polinomial model given by
  $$
  {\bf z} = T({\bf x}) = (1, x_0, x_0^2, \ldots, x_0^{g-1})^\top.
  $$
Compute matrices Ztrain and Ztest that result from applying the polynomial transformation to the inputs in X0train and X0test for a model with degree g_max = 50. The np.vander() method may be useful for this.
Note that, despite X0train and X0test where normalized, you will need to re-normalize the transformed variables.
Note, also, that the first component of the transformed variables, which must be equal to 1, should not be normalized. To simplify the job, the code below defines a normalizer class that performs normalization to all components unless for the first one.
Can you write Python program for it?
 Can you provide a Python program to compute matrices Ztrain and Ztest that result from applying the polynomial transformation to the inputs in X0train and X0test for a model with degree g_max = 50?
assistant
#Here is Python program to compute matrices Ztrain and Ztest that result from applying the polynomial transformation to the inputs in X0train and X0test for a model with degree g_max = 50.

# The following normalizer will be helpful: it normalizes all components of the 
# input matrix, unless for the first one (the "all-one's" column) that
# should not be normalized
class Normalizer():
    """
    A data normalizer. Usage:
        nm = Normalizer()
        Z = nm.fit_transform(X)  # to estimate the normalization mean and variance an normalize 
                                 # all columns of X unles the first one
        Z2 = nm.transform(X)     # to normalize X without recomputing mean and variance parameters
   """
    
    def fit_transform(self, Z):
        
        self.mean_z = np.mean(Z, axis=0)
        self.mean_z[0] = 0
        self.std_z = np.std(Z, axis=0)
        self.std_z[0] = 1
        Zout = (Z - self.mean_z) / self.std_z
        
        # sc = StandardScaler()
        # Ztrain = sc.fit_transform(Ztrain)
        return Zout
        
    def transform(self, Z):        
        return (Z - self.mean_z) / self.std_z
        # Ztest = sc.transform(Ztest)      
        
# Set the maximum degree of the polynomial model
g_max = 50

# Compute polynomial transformation for train and test data
# <SOL>
Ztrain = np.vander(X0train.flatten(), g_max + 1, increasing=True)
Ztest = np.vander(X0test.flatten(), g_max + 1, increasing=True)
# </SOL>

# Normalize training and test data 
# <SOL>
nm = Normalizer()
Ztrain = nm.fit_transform(Ztrain)
Ztest = nm.transform(Ztest)
# </SOL>