data_all = [data.TV data.Radio data.Newspaper data.Sales];
train_all = [train.TV train.Radio train.Newspaper train.Sales];
ntrain=max(size(train_all));
ndata=max(size(data_all));
for i = 1:ntrain
	val=train_all(i,1:3);
	for j = 1:ndata
		dist(j) = norm(data_all(j,1:3)-val);
	end
	[t,idx]=sort(dist);
	y=data_all(idx,4);
	y_predict(i) = y(1);
	rmse=rmse+(train_all(i,4)-y(1)).^2;
end
rmse=sqrt(rmse/ntrain);
figure
plot(train_all(:,4),y_predict,'or','LineWidth',1.5)
xlabel('Real value for sales of training dataset')
ylabel('Predicted value for sales of training dataset')
title("RMSE = " + rmse);
