This repository implements Linear Discriminant Analysis (LDA), a machine learning algorithm for dimensionality reduction and classification, using Node.js. LDA projects high-dimensional data onto a lower-dimensional space while maximizing class separation, making it particularly effective for supervised learning tasks.
- 📊 Implementation of Linear Discriminant Analysis in Node.js
- 🔍 Dimensionality reduction capabilities
- 📈 Data visualization tools
- 🧪 Example datasets with visualizations
- 📝 Detailed implementation guide
- Node.js 18.x or higher
- npm (Node Package Manager)
- Clone the repository:
git clone https://github.com/itsumarsoomro/linear-discriminant-analysis-LDA-ML.git
cd linear-discriminant-analysis-LDA-ML
- Install dependencies:
npm install
- Start the server:
npm start
linear-discriminant-analysis-LDA-ML/
│
├── server.js # Main application file
├── package.json # Project dependencies
├── package-lock.json # Dependency lock file
└── README.md # Project documentation
After starting the server, navigate to http://localhost:3000
in your web browser to access the application.
// Sample code from ldaController.js
const performLDA = (data, labels) => { // Calculate class means const classMeans = calculateClassMeans(data, labels);
// Calculate scatter matrices const { withinClassScatter, betweenClassScatter } = calculateScatterMatrices(data, labels, classMeans);
// Calculate eigenvalues and eigenvectors const { eigenvalues, eigenvectors } = calculateEigen(withinClassScatter, betweenClassScatter);
// Project data onto lower dimension const projectedData = projectData(data, eigenvectors);
return projectedData; };
Performs LDA on the provided dataset.
Request body:
{
"data": [[1, 2, 3], [4, 5, 6], ...],
"labels": [0, 1, 0, ...],
"dimensions": 2
}
Response:
{
"projectedData": [[1.2, 2.3], [4.5, 5.6], ...],
"accuracy": 0.95
}
Retrieves the results of the LDA analysis.
Response:
{
"originalDimensions": 4,
"reducedDimensions": 2,
"classificationAccuracy": 0.95,
"visualizationUrl": "/images/lda_plot.png"
}
The implementation demonstrates:
- Successful dimensionality reduction
- Clear class separation in the projected space
- High classification accuracy
- Interactive visualization of results
Results can be viewed in the web interface or accessed via the API endpoints.
Contributions are welcome! To contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Umar Soomro - @itsumarsoomro
Project Link: https://github.com/itsumarsoomro/linear-discriminant-analysis-LDA-ML