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 🙏

© 2026 – Pkg Stats / Ryan Hefner

skjson-js

v1.0.3

Published

Zero-dependency universal inference library for skjson models

Readme

skjson-js

skjson-js is a zero-dependency, universal Javascript inference library for Python skjson exported models. It parses the JSON representation of trained scikit-learn models and accurately executes inference directly in Node.js or any browser environment.

Live Demo

Features

  • Zero dependencies: No web assembly, no native bindings, pure Javascript/TypeScript.
  • Universal compatibility: Works effortlessly in browsers and Node.js.
  • 100% Mathematical Parity: Strict test suites guarantee identical predictions compared to Python scikit-learn outcomes.

Installation

npm install skjson-js

Supported Models

Currently, skjson-js supports inference for the following model types:

  • Linear Models: LinearRegression, LogisticRegression, Ridge, Lasso
  • Trees & Forests: DecisionTreeClassifier, DecisionTreeRegressor, RandomForestClassifier, RandomForestRegressor
  • Naive Bayes: GaussianNB
  • Support Vector Machines: SVC, SVR (with linear kernels)
  • Nearest Neighbors: KNeighborsClassifier, KNeighborsRegressor
  • Preprocessing: StandardScaler, MinMaxScaler

Usage Example

First, export your model in Python using skjson:

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
import skjson

# Load the Iris dataset and split
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a Random Forest classifier
clf = RandomForestClassifier(random_state=42)
clf.fit(X_train, y_train)

# Export the trained model to JSON
skjson.save(clf, 'model.json')

Then, load and predict in Javascript:

import { loadModel } from 'skjson-js';
import myModelJson from './model.json'; // Or fetch() in the browser

// Instantiate the predictor
const predictor = loadModel(myModelJson);

// Perform inference
const predictions = predictor.predict([
  [2.3, -1.0, 0.4, 5.0],
  [0.5,  0.2, 0.1, -1.1]
]);
console.log('Predictions:', predictions);

// For classification models, you can also get probabilities
if (predictor.predict_proba) {
  const probas = predictor.predict_proba([
    [2.3, -1.0, 0.4, 5.0]
  ]);
  console.log('Probabilities:', probas);
}

Preprocessing Example

import { loadModel } from 'skjson-js';
import scalerJson from './scaler.json';

const scaler = loadModel(scalerJson);

// Transformers use the `.transform()` method instead of predict()
const transformed = scaler.transform([
  [2.3, -1.0, 0.4, 5.0],
  [0.5,  0.2, 0.1, -1.1]
]);
console.log('Transformed:', transformed);

HTML-Only Usage (Browser via CDN)

You can use skjson-js directly in plain HTML without any bundlers by utilizing modern ES modules and a CDN like unpkg.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>skjson-js HTML Demo</title>
</head>
<body>
    <h1>Prediction Result: <span id="result">Loading...</span></h1>

    <script type="module">
        // Import directly from a CDN
        import { loadModel } from 'https://unpkg.com/skjson-js/dist/index.js';

        async function run() {
            // Fetch your JSON model from a local path or URL
            const response = await fetch('./model.json');
            const modelJson = await response.json();

            // Load and predict
            const predictor = loadModel(modelJson);
            const preds = predictor.predict([[2.3, -1.0, 0.4, 5.0]]);
            
            document.getElementById('result').innerText = preds[0];
        }

        run();
    </script>
</body>
</html>

Security

This package operates with 0 runtime dependencies to ensure full immunity against supply-chain attacks. CI enforces npm audit on all development tools prior to publishing.

AI use

This project uses AI-assisted development with Gemini and Claude Opus.

License

ISC