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 🙏

© 2024 – Pkg Stats / Ryan Hefner

tfjs-metrics

v0.0.6

Published

A set of basic performance metrics for TensorFlow.js in Angular. Those metrics are used to validate your model after training. It was created to be used together with TensorFlow.js

Downloads

1

Readme

TfjsMetrics

This package was created to support people working with TensorFlow.js. Different from TensorFlow in Python, we do not have such a library. When you publish a scientific paper, you may be asked to calculate those measures. Even though you can use @tensorflow/tfjs-vis to see the loss function and the accuracy, reviewers may ask for more.

This package will give you already ready to use a set of basic metrics for scientific papers.

Getting ready

It is a service where we implemented the metrics.

Import the service to your component import { TfjsMetricsService } from 'tfjs-metrics';

Then, inject the service on your component:

constructor(private readonly tfmetrics: TfjsMetricsService){}

Now, it is ready to be called, and used!

Confusion matrix

This matrix will calculate how your model is doing, if it is confusing the classes.

const confusion_matrix: any = await this.tfmetrics.confusionMatrix(model, features_test, target_test)

Where: model is your TFJS model, trained. features_test are your features, features_test are the respective labels.

Tip. separate those samples from the training process, for making sure your model was able to generalize. Those are vectors and matrix, not tensors. We transform into tensors ourselves. It was tested for numbers, not yet for computer vision.

Tip. the features and target should be arrays. E.g., With two features feature = [[1 2 3], [2 3 4]] target = [ 1 0]

Real example:

This example is when you are using await this.dataset.forEachAsync, an internal routine from TFJS for working with datasets uploaded from CSV files.

features_test.push(Object.values(e.xs));

There is an array to store the features; and also the target/labels. Object.values will transform the object into array elements, for pushing, in case it is as an object.

Then, we also save the respective label, which we need to compare the expected label vs. predicted one by the model.

target_test.push(e.ys.diabetes);

See paper: [Machine learning in medicine using JavaScript: building web apps using TensorFlow.js for interpreting biomedical datasets] (https://www.medrxiv.org/content/10.1101/2023.06.21.23291717v2.full)

Basic training metrics

We should measure how our models generalized. Those are basic metrics you can use, and they are largely accepted.

const performance= this.tfmetrics.performance_metrics(confusion_matrix)

Where: confusion_matrix is the confusion matrix.

It will calculate:

  • F1 score;
  • recall
  • precision

Limitations

Those metrics were created for binary classification, it will not work as intented for multi-class classification problems.

Further help

Let me know your thoughts on [email protected]