Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kspilario authored May 29, 2023
1 parent a14cfd7 commit e1e0f73
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Linear_and_Logistic_Regression/LWR_gif.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
clc; close all; rng(0);

% Generate Sine Data Set
N = 100; % No. of training points
x = linspace(0,12,N)'; % Training data, x
y = sin(x) + 0.5*rand(N,1); % Training data, y
y = (y - mean(y))./std(y); % Standard scaling on y

scatter(x,y,'b','filled','MarkerFaceAlpha',0.3);
grid on; box on; set(gcf,'Color','w');

xp = linspace(-2,14,200)'; % Finely spaces x values
yp = zeros(size(xp));

for tau = 0.1:0.02:3
weighting = @(x,X,tau) exp(-(x-X).^2/(2*tau^2));
for j = 1:length(xp)
W = diag(weighting(xp(j),x,tau));
X = [ones(N,1), x];
w = (X'*W*X)\(X'*W*y); % Locally weighted linear reg.
yp(j) = [1 xp(j)]*w; % Predict on xp(j)
end

hold on; p = plot(xp,yp,'k','LineWidth',1.5);
set(gcf,"Position",[488,506.6,560,255.4]);
title(sprintf('LWR, tau = %.4f',tau))
axis([-2 14 -3 3]);

% For creating a GIF
% exportgraphics(gcf,'LWR_tau.gif','Append',true);

pause(0.5); delete(p);
end
Binary file added Linear_and_Logistic_Regression/LWR_tau.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e1e0f73

Please sign in to comment.