Implementation of machine learning algorithms from Andrew Ng's Coursera course, originally developed in MATLAB/OCTAVE as part of the programming assignments.
This repository contains:
- MATLAB implementations of core ML algorithms
- Solutions to Coursera programming exercises
- Helper functions used in the course
Algorithm | MATLAB Files | Course Week |
---|---|---|
Linear Regression | linearReg.m , gradientDescent.m |
Week 2 |
Logistic Regression | logisticReg.m , costFunction.m |
Week 3 |
Neural Networks | nnCostFunction.m , predict.m |
Week 4 |
Support Vector Machines | svmTrain.m , gaussianKernel.m |
Week 7 |
K-Means & PCA | kMeans.m , pca.m |
Week 8 |
- Ensure you have MATLAB installed (R2020b or later recommended)
- Clone this repository:
git clone https://github.com/imbilalbutt/Machine-learning-algorithms.git
- Add the project folder to MATLAB path:
addpath(genpath('/path/to/repository'));
For users without MATLAB:
- Install GNU Octave
- All files are compatible with Octave 6.0+
% Load data
data = load('ex1data1.txt');
X = data(:, 1); y = data(:, 2);
% Run gradient descent
theta = gradientDescent(X, y, zeros(2,1), 0.01, 1500);
% Plot results
plot(X(:,2), y, 'rx', 'MarkerSize', 10);
hold on;
plot(X(:,2), X*theta, '-');
% Load pre-trained weights
load('ex3weights.mat');
% Make predictions
pred = predict(Theta1, Theta2, X);
accuracy = mean(double(pred == y)) * 100;
fprintf('Training Set Accuracy: %f\n', accuracy);
MATLAB File | Corresponding Exercise |
---|---|
ex1.m |
Linear Regression with One Variable |
ex2.m |
Logistic Regression |
ex3.m |
Multi-class Classification with NNs |
ex4.m |
Neural Network Backpropagation |
ex5.m |
Bias-Variance Analysis |
ex6.m |
Support Vector Machines |
ex7.m |
K-Means & PCA |
- Original MATLAB/OCTAVE implementations as done in the course
- Vectorized operations for efficient computation
- Detailed comments explaining each step
- Visualization scripts for algorithm behavior
- File naming follows Coursera's original structure
- All functions are self-contained (no toolboxes required)
- Test data included in
/data
directory
While this is primarily a course repository, improvements are welcome:
- Bug fixes in implementations
- Additional documentation
- Performance optimizations
Please maintain MATLAB/OCTAVE compatibility when submitting changes.
MIT License - See LICENSE for details.
- Andrew Ng and Stanford University for the course materials
- Coursera for hosting the content
- MathWorks for MATLAB development environment
Key differences from the Python version:
1. **MATLAB-specific setup instructions**
2. **Original course file structure** preserved
3. **MATLAB code examples** with proper syntax
4. **Octave compatibility** noted
5. **Exercise mapping** to original Coursera problems
6. **No dependency management** (MATLAB doesn't use pip/requirements.txt)
Would you like me to:
1. Add specific MATLAB debugging tips?
2. Include screenshots of example outputs?
3. Add a comparison between MATLAB and Python implementations?