Skip to content

Conventional Machine learning models like Linear regression, Logistic regression and Neural network for mulitclassification are implemented in MATLAB.

Notifications You must be signed in to change notification settings

imbilalbutt/Machine-learning-algorithms

Repository files navigation

Machine Learning Algorithms (MATLAB Implementation)

License: MIT MATLAB

Implementation of machine learning algorithms from Andrew Ng's Coursera course, originally developed in MATLAB/OCTAVE as part of the programming assignments.

📌 Project Overview

This repository contains:

  • MATLAB implementations of core ML algorithms
  • Solutions to Coursera programming exercises
  • Helper functions used in the course

🧠 Algorithms Implemented

Core Algorithms

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

🛠️ Setup Instructions

MATLAB Installation

  1. Ensure you have MATLAB installed (R2020b or later recommended)
  2. Clone this repository:
    git clone https://github.com/imbilalbutt/Machine-learning-algorithms.git
  3. Add the project folder to MATLAB path:
    addpath(genpath('/path/to/repository'));

OCTAVE Alternative

For users without MATLAB:

  1. Install GNU Octave
  2. All files are compatible with Octave 6.0+

📊 Running the Code

Example: Linear Regression

% 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, '-');

Example: Neural Networks

% 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);

📈 Course Exercise Mapping

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

🔍 Key Features

  • Original MATLAB/OCTAVE implementations as done in the course
  • Vectorized operations for efficient computation
  • Detailed comments explaining each step
  • Visualization scripts for algorithm behavior

📝 Notes for Developers

  1. File naming follows Coursera's original structure
  2. All functions are self-contained (no toolboxes required)
  3. Test data included in /data directory

🤝 Contribution Guidelines

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.

📜 License

MIT License - See LICENSE for details.

🙏 Acknowledgments

  • 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?

About

Conventional Machine learning models like Linear regression, Logistic regression and Neural network for mulitclassification are implemented in MATLAB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages