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

stanford-classifier

v2.0.1

Published

Nodejs wrapper for Stanford classifier.

Downloads

13

Readme

Major Updates :

Available Methods :

stanfordClassifier.train(string)

stanfordClassifier.trainAll(array)

stanfordClassifier.syncClassifier()

stanfordClassifier.getDataArray()

stanfordClassifier.getValuesArray()

stanfordClassifier.getFeatureCounts()

stanfordClassifier.getLabelsArray()

stanfordClassifier.getLabelsArray()

stanfordClassifier.trimData()

stanfordClassifier.trimLabels()

stanfordClassifier.trimToSize(int)

stanfordClassifier.numClass()

stanfordClassifier.numDatumsPerLabel()

stanfordClassifier.numFeatures()

stanfordClassifier.numFeatureTokens()

stanfordClassifier.numFeatureTypes()

stanfordClassifier.printSparseFeatureMatrix()

stanfordClassifier.printSVMLightFormat()

stanfordClassifier.randomize(int)

stanfordClassifier.size()

stanfordClassifier.summaryStatistics()

Getting Started

Install the stanford-classifier Node.js module from the npm repository. The stanford-classifier Node.js module uses Stanford Classifier v3.5.2 internally and has node-java as a dependency. Your environment should have Java properly configured to work with node-java. You can learn more about node-java configurations here. To install the stanford-classifier run the following in the terminal:

npm install stanford-classifier --save

The module will appear in the projects root node_modules directory. The Node.js module can be viewed in the npm repository https://www.npmjs.com/package/stanford-classifier.

Dataset

The classifier needs to be trained with pre-trained data. Without trained data, the classifier will not work as expected and will not be accurate. Regardless of which classification algorithm is being used, the classifier needs a robust dataset to yield accurate classifications. I built a small dataset that contains organization and band Twitter descriptions. The dataset can be used to train the stanford-classifier. It can be downloaded here.

Training And Classifying The Classifier

The train() method is used to train the stanford-classifier with a pre-trained dataset. Here is an example of how to use the train() method to train the stanford-classifier.

Example :

/// Dependencies
var stanfordClassifier = require('stanford-classifier');
var byline = require('byline');
var fs = require('fs');

/// Initialize the Stanford Classifier
var sc = new stanfordClassifier();


var mem = [];

/// Create a stream to read the dataset
var stream = byline(fs.createReadStream('dataset.txt', {
    encoding: 'utf8'
}));

/// Push each line into memory
stream.on('data', function(line) {
    mem.push(line);
});

/// Use the training dataset in memory to train the classifier dataset
stream.on('end', function() {
    for (var i = 0; i < mem.length; i++) {
        var line = mem[i];
        sc.train(line);
    }

/// Sync the classifier with the classifiers dataset
    sc.syncClassifier();
  
/// Use the classifier
  console.log(sc.classify('Our Twitter run by the band and crew to give you an inside look into our lives on the road'));
/// BAND
});

After the classifier has been trained use the syncClassifier() method to sync the trained dataset with the classifier.

Customizing The Classifier

Options can be sent directly to the classifier when initializing the stanford-classifier instance.

var sc = new stanfordClassifier(options);

The options can either be a path to a property file or an object. The default options are the following :

#
# Features
#
useClassFeature=true
1.useNGrams=true
1.usePrefixSuffixNGrams=true
1.maxNGramLeng=4
1.minNGramLeng=1
1.binnedLengths=10,20,30
#
# Printing
#
# printClassifier=HighWeight
printClassifierParam=200
#
# Mapping
#
goldAnswerColumn=0
displayedColumn=1
#
# Optimization
#
intern=true
sigma=3
useQN=true
QNsize=15
tolerance=1e-4

other options that can be used are here.

Blog : http://www.mbejda.com/using-the-stanford-classifier-with-node/