This project implements a binary linear classifier and performs linear regression using the gradient descent algorithm. Two separate tasks are performed:
-
Binary Linear Classifier: The project constructs a binary linear classifier for each class against the rest using the Iris dataset. It utilizes a simple linear regression-based approach with a threshold to classify samples into two classes.
-
Linear Regression with Gradient Descent: The project implements linear regression using the gradient descent optimization algorithm. It fits a linear equation to noisy data points generated from a linear function and calculates the mean squared error to evaluate the model's performance.
- Python 3.x
-
Clone the repository or download the project files.
-
Navigate to the project directory:
cd path_to_your_project_directory
-
Create a virtual environment:
- For Linux/Mac:
python3 -m venv venv_name
- For Windows:
python -m venv venv_name
- For Linux/Mac:
-
Activate the virtual environment:
- For Linux/Mac:
source venv_name/bin/activate
- For Windows:
venv_name\Scripts\activate
- For Linux/Mac:
-
Install the required libraries using
requirements.txt
:pip install -r requirements.txt
-
Run the project:
python main.py
main.py
: Main script containing the implementation of binary linear classifier and linear regression with gradient descent.README.md
: This file providing an overview of the project.requirements.txt
: File containing the list of required libraries.
- The
fit()
function constructs binary linear classifiers for each class against the rest using the Iris dataset. - The
predict()
function predicts the class label for test data using the constructed classifiers. - Accuracy scores for each class model are printed.
- The project generates noisy data points from a linear function and performs linear regression using gradient descent.
- The
linear_eq()
function defines the linear equation. - The
mean_squared_error()
function calculates the mean squared error between predicted and true values. - The
gradient_descent()
function implements the gradient descent optimization algorithm to fit the best line to the data points. - The best fit line equation and mean squared error are printed.
- A scatter plot with the training data and the best fit line is displayed.
This project is licensed under the MIT License - see the LICENSE
file for details.