Skip to content

A light weight machine learning library published on npmjs

Notifications You must be signed in to change notification settings

ArgonzCompany/Argonz-ML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Machine Learning Library

This is a lightweight JavaScript library for implementing various machine learning algorithms. The library includes the following algorithms:

  1. Linear Regression
  2. Logistic Regression
  3. Support Vector Machine (SVM)
  4. Decision Tree
  5. Random Forest
  6. XGBoost

The library is designed to be modular, easy to use, and extensible. Below is the documentation for installation, usage, and examples.


Table of Contents

  1. Installation
  2. Usage
  3. Model Class
  4. Examples
  5. Running the Code

Installation

To use this library, you need to have Node.js and npm installed. Follow these steps:

  1. Clone the repository or download the source code.

  2. Navigate to the project directory.

  3. Install the required dependencies:

    npm install mathjs
  4. Import the library into your project:

    const { Model } = require('argonz-ml');

Usage

The library provides a unified Model class to instantiate and use any of the supported algorithms. Below are the details for each algorithm.

Linear Regression

  • Description: A linear regression model with Ridge regularization.
  • Options:
    • lambda (default: 0.01): Regularization parameter.
const model = new Model('linear_regression', { lambda: 0.01 });

Logistic Regression

  • Description: A logistic regression model for binary classification.
  • Options:
    • learningRate (default: 0.01): Learning rate for gradient descent.
    • iterations (default: 1000): Number of training iterations.
const model = new Model('logistic_regression', { learningRate: 0.01, iterations: 1000 });

SVM

  • Description: A Support Vector Machine (SVM) for binary classification.
  • Options:
    • learningRate (default: 0.01): Learning rate for gradient descent.
    • lambda (default: 0.1): Regularization parameter.
    • iterations (default: 1000): Number of training iterations.
const model = new Model('svm', { learningRate: 0.01, lambda: 0.1, iterations: 1000 });

Decision Tree

  • Description: A decision tree for classification or regression.
  • Options:
    • maxDepth (default: 5): Maximum depth of the tree.
const model = new Model('decision_tree', { maxDepth: 5 });

Random Forest

  • Description: A random forest ensemble of decision trees.
  • Options:
    • nTrees (default: 10): Number of trees in the forest.
    • maxDepth (default: 5): Maximum depth of each tree.
    • featureSubsetSize (default: sqrt(nFeatures)): Number of features to consider for each split.
const model = new Model('random_forest', { nTrees: 10, maxDepth: 5 });

XGBoost

  • Description: An implementation of the XGBoost algorithm for regression.
  • Options:
    • nTrees (default: 10): Number of trees.
    • learningRate (default: 0.1): Learning rate.
    • maxDepth (default: 3): Maximum depth of each tree.
    • lambda (default: 1.0): Regularization parameter.
const model = new Model('xgboost', { nTrees: 10, learningRate: 0.1, maxDepth: 3, lambda: 1.0 });

Model Class

The Model class provides a unified interface for training, predicting, and evaluating models.

Methods

  1. train(X, y):

    • Trains the model on the input data X and target labels y.
  2. predict(X):

    • Predicts the target values for the input data X.
  3. evaluate(yTrue, yPred):

    • Evaluates the model's performance by comparing true labels yTrue with predicted labels yPred.

Examples

Example 1: Linear Regression

const { Model } = require('argonz-ml');

// Example data
const X = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12]
];
const y = [10, 20, 30, 40];

// Create and train the model
const model = new Model('linear_regression', { lambda: 0.01 });
model.train(X, y);

// Make predictions
const predictions = model.predict(X);

// Evaluate the model
const evaluation = model.evaluate(y, predictions);

console.log("Predictions:", predictions);
console.log("Evaluation:", evaluation);

Example 2: Logistic Regression

const { Model } = require('argonz-ml');

// Example data
const X = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12]
];
const y = [0, 1, 0, 1]; // Binary classification

// Create and train the model
const model = new Model('logistic_regression', { learningRate: 0.01, iterations: 1000 });
model.train(X, y);

// Make predictions
const predictions = model.predict(X);

// Evaluate the model
const evaluation = model.evaluate(y, predictions);

console.log("Predictions:", predictions);
console.log("Evaluation:", evaluation);

Example 3: Random Forest

const { Model } = require('argonz-ml');

// Example data
const X = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12]
];
const y = [0, 1, 0, 1]; // Binary classification

// Create and train the model
const model = new Model('random_forest', { nTrees: 10, maxDepth: 5 });
model.train(X, y);

// Make predictions
const predictions = model.predict(X);

// Evaluate the model
const evaluation = model.evaluate(y, predictions);

console.log("Predictions:", predictions);
console.log("Evaluation:", evaluation);

Running the Code

  1. Save the code in a file, e.g., example.js.

  2. Run the file using Node.js:

    node example.js
  3. You should see the predictions and evaluation metrics printed in the console.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.


Contact

For questions or feedback, please contact Argonz Company.


Enjoy using the Machine Learning Library! 🚀