Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Error in Machine learning code I can not correct. Please help solve L = 100; N = 25; X = rand(N, L); t = sin(2

Error in Machine learning code I can not correct. Please help solve

image text in transcribed

L = 100; N = 25; X = rand(N, L);

t = sin(2 * pi * X) + 0.3 * randn(N, L);

lambda = [0.01, 0.1, 1];

s = 0.1;

M = 100; % Number of basis functions

X_test = rand(1000, 1);

for i = 1:length(lambda)

for j = 1:L

X_train = X(:, j);

t_train = t(:, j);

% % Constructing the design matrix using Gaussian basis functions

mu = linspace(0, 1, M);

Phi_train = exp(-(X_train - mu').^2 / (2 * s^2));

Phi_test = exp(-(X_test - mu').^2 / (2 * s^2));

%

% Solving for the weights using regularized least squares

w = (Phi_train * Phi_train' + lambda(i) * eye(M)) \ (Phi_train * t_train');

% Predicting the target values for the test data

t_test(:, j) = Phi_test * w;

end

% Computing the bias, variance, and test error for each value of lambda

f_bar = mean(t_test, 2);

bias_sq = mean((f_bar - sin(2 * pi * X_test)).^2);

variance = mean(mean((t_test - f_bar).^2));

test_error(i) = bias_sq + variance;

end

figure;

plot(log10(lambda), bias_sq * ones(size(lambda)), 'k--', 'LineWidth', 2);

hold on;

plot(log10(lambda), variance * ones(size(lambda)), 'k-.', 'LineWidth', 2);

plot(log10(lambda), test_error, 'k-', 'LineWidth', 2);

xlabel('log_{10}(\lambda)');

ylabel('Error');

legend('Bias^2', 'Variance', 'Test Error');

X_test = rand(1000, 1);

t_test = sin(2 * pi * X_test) + 0.3 * randn(1000, 1);

1. Generate the data set D as follows: a. L=100 b. N=25 c. X contains samples from a uniform distribution U(0,1). d. t=sin(2X)+, where contains samples from a Gaussian distribution N(0,=0.3) 2. Select a set of permissible values for the regularization parameter . 3. For each value of , use the method of "linear regression with non-linear models" to fit Gaussian basis functions to each of the datasets. Use s=0.1. 4. Produce the plot as shown below, where f(x)=L1l=1Lf(l)(x)(bias)2=N1n=1N[f(x(n))h(x(n))]2variance=N1n=1NL1l=1L[f(l)(x(n))f(x(n))]2 5. The test error curve is the average error for a test data set of 1000 points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

\f\f\f\f\f\f

Answered: 1 week ago

Question

8-15 Explain how a cyberattack can be carried out.

Answered: 1 week ago

Question

Question What is a Roth 401(k) feature?

Answered: 1 week ago

Question

Question Can employees make contributions to a profit sharing plan?

Answered: 1 week ago