npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

js-ml-lib

v0.1.2

Published

A simple machine learning library in JavaScript/TypeScript

Readme

Introduction

js-ml-lib is a lightweight machine learning library built with JavaScript and TypeScript. It provides essential tools for machine learning tasks, including basic models and data preprocessing utilities. The library is designed for developers looking to implement machine learning workflows in JavaScript or TypeScript environments, with functionality inspired by Python's scikit-learn.

Key Features

  • Models:
    • Linear Regression Model: A simple and efficient implementation of the linear regression algorithm for training and prediction.
    • SGDRegressor: A simple and efficient implementation of the stochastic gradient descent regression algorithm for training and prediction.
  • Data Preprocessing:
    • Standardization (StandardScaler): Scales data to have a mean of 0 and a variance of 1.
    • Normalization (MinMaxScaler): Scales data to fit within a specified range, such as [0, 1].
  • Dataset Splitting: Utilities to split datasets into training and testing sets for machine learning experiments.

Quick Start

Installation

Before installing, ensure you have Node.js and npm installed. To set up the library, run the following command in your project's root directory:

npm install js-ml-lib

Usage

Models

Linear Regression

The LinearRegression class allows you to train a model on a dataset and make predictions. Below is a simple example:

import { LinearRegression } from "js-ml-lib";

// Training data
const X = [[1], [2], [3], [4]];
const y = [2, 4, 6, 8];

// Initialize and train the model
const model = new LinearRegression();
model.fit(X, y);

// Make predictions
const predictions = model.predict([[5], [6]]);
console.log(predictions); // Output: [10, 12]
SGDRegressor

The SGDRegressor class allows you to train a model on a dataset and make predictions using the stochastic gradient descent regression algorithm. Below is a simple example:

import { SGDRegressor } from "js-ml-lib";

// Training data
const X = [[1], [2], [3], [4]];
const y = [2, 4, 6, 8];

// Initialize and train the model
const model = new SGDRegressor();
model.fit(X, y);

// Make predictions
const predictions = model.predict([[5], [6]]);
console.log(predictions); // Output: [10, 12]

Data Preprocessing

Standardization

Standardize features by scaling them to have a mean of 0 and a variance of 1. This is especially useful when working with algorithms sensitive to feature magnitude.

import { StandardScaler } from "js-ml-lib";

const X = [
  [1, 2],
  [2, 3],
  [3, 4],
];

// Initialize and fit the scaler
const scaler = new StandardScaler();
scaler.fit(X);

// Transform the data
const X_scaled = scaler.transform(X);
console.log(X_scaled);
Normalization

Normalize features to fit within a specified range (default: [0, 1]).

import { MinMaxScaler } from "js-ml-lib";

const X = [
  [1, 2],
  [2, 3],
  [3, 4],
];

// Initialize and fit-transform the scaler
const scaler = new MinMaxScaler();
const X_scaled = scaler.fitTransform(X);
console.log(X_scaled);

Dataset Splitting

Easily split data into training and testing sets using trainTestSplit.

import { trainTestSplit } from "js-ml-lib";

const data = [1, 2, 3, 4, 5];

// Split the data (80% training, 20% testing)
const { train, test } = trainTestSplit(data, 0.2);

console.log(train); // Example output: [1, 2, 3, 4]
console.log(test); // Example output: [5]

For Developers

Testing

This library uses Jest for testing. To run the test suite, use the following command:

npm test

Directory Structure

The library's source code and tests are organized as follows:

├── src/
│   ├── models/           # Implementation of machine learning models
│   ├── preprocessing/    # Data preprocessing tools
│   ├── validation/       # Dataset splitting utilities
│   ├── utils/            # General utility functions
├── tests/                # Unit and integration tests
├── package.json          # Package configuration
├── LICENSE               # License file
└── README.md             # Project documentation

Contributing

We welcome contributions to improve and expand the library. Please adhere to the following guidelines:

  1. Fork the repository and create a new feature branch.
  2. Ensure all new code includes appropriate tests.
  3. Run the test suite (npm test) to confirm that all tests pass.
  4. Submit a pull request for review.

License

This project is licensed under the MIT License. You are free to use, modify, and distribute the library under the terms of this license.


Support and Contact

If you have any questions, suggestions, or issues, feel free to reach out to the project maintainer. We are always open to feedback and ideas to enhance the library.


By leveraging js-ml-lib, you can build powerful machine learning workflows directly within your JavaScript or TypeScript projects. We look forward to your contributions and feedback to make this library even better!