Skip to content

Instantly share code, notes, and snippets.

View achrafsoltani's full-sized avatar

Achraf Soltani achrafsoltani

View GitHub Profile
disp("Initilizing the best Linear Regression Program v1.0\n");
% clear and initialize
clear; clc; close all;
sprintf("Initilizing paths...\n");
% add paths
addpath('./lib');
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
7.4764,4.3483
8.5781,12
6.4862,6.5987
5.0546,3.8166
function parameters = gradient_descent(X, Y, theta0, theta1, learning_rate, initial_cost)
i = 0;
previous_cost = initial_cost+1;
cost = initial_cost;
m = length(X);
while(i < 100)
H = theta0 + theta1.*X;
cost = compute_cost(H, Y, m);
format short
derivatives = compute_derivatives(X, Y, theta0, theta1, m);
function derivatives = compute_derivatives(X, Y, theta0, theta1, m)
derivatives(1) = (1/m)*sum((theta0+(theta1*X))-Y);
derivatives(2) = (1/m)*sum(X.*((theta0+(theta1*X))-Y));
end
% Explanatory Variable
X2 = [1;1;2;3;3];
% Response Variable
Y2 = [0.5;1.5;2;1.5;3];
plot(X2, Y2, 'rx', 'linewidth',2);
axis([0 5 0 5])
@achrafsoltani
achrafsoltani / cost_function.m
Created April 17, 2022 22:56
Cost function
function cost = compute_cost(H, Y, m)
% H hypothesis matrix
% Y Response Variable
% m training examples
cost = (1/(2*m))*sum((H-Y).^2);
end
@achrafsoltani
achrafsoltani / main_1.m
Last active April 17, 2022 22:55
Getting started with linear regression on Matlab from scratch
disp("Initilizing the best Linear Regression Program v1.0\n");
% clear and initialize
clear; clc; close all;
sprintf("Initilizing paths...\n");
% add paths
addpath('./lib');
@achrafsoltani
achrafsoltani / countries.sql
Created February 6, 2018 12:16 — forked from adhipg/countries.sql
Sql dump of all the Countries, Country Codes, Phone codes.
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;