function [y_predict] = smoothingParameter2(x_train,y_train, x_predict)
% for choosing the smoothing parameter datedependent
    %we split the sample D_n into a learning and a testing sample. We use
    %the learning sample to compute the regression estimate and the testing
    %sample for choosing the best bandwidth h, which minimizes the
    %empirical L2 risk
    
n=size(x_train,1);
nl= ceil(n/2);

x_learning = x_train(1:nl,:);
y_learning = y_train(1:nl,:);
x_testing = x_train((nl+1):n,:);
y_testing = y_train((nl+1):n,:);

nt=size(x_testing,1);

m=(-10):10;
%set bandwidth
hi=2.^m;

l=size(hi,2);

%[y_predict_t] =zeros(nt,l);
y_h= zeros(nt,2);

    
%compute regression estimate with learning sample, and use X-values
%of testing sample for the empirical error
y_predict_t = k(x_learning,y_learning,x_testing,hi);
    
for s=1:l;
    %compute the empirical error mit Y-values of the testing sample, save
    %the result and the corresponding bandwidth in a 2-dim. matrice
    y_h(s,1)= (1/(nt))* sum((y_predict_t(:,s) - y_testing).^2); 
    y_h(s,2)=hi(1,s);
    
end


%determine the minimal empirical L2 risk and remember the position
[c,i]=min(y_h(:,1));
%bandwidth is the value on the position i in the second column
h= y_h(i,2);
%now do regression estimate again with the predicted x-values
y_predict=k(x_learning,y_learning,x_predict,h);  




end