-

- -

Monday, October 8, 2018

Using ObservableHq Online (Notebook) Editor For JavaScript ML Programming Like Python Jupyter Notebook

 


.

Observable is not just another JavaScript sandbox. It introduces the notebook paradigm to JavaScript projects, those of you familiar with Jupyter notebooks, this is the equivalent with JavaScript instead of Python. It turns out JavaScript is very well-suited to this type of paradigm.

What’s more, JavaScript developers already have some sort of familiarity with reactivity since most frontend frameworks and view libraries build on it. It’s a different kind of reactivity, in that the library only re-renders or re-computes the section of the application that needs it (cf. Vue, Angular, React).

.

https://codewithhugo.com/observablehq-notebooks-for-javascript-demos-and-prototypes/

Thursday, October 4, 2018

The Difference Between Machine Learning and Neural Networks



.

A neural network (also called an “artificial neural network”) is a type of machine learning model that is usually used in supervised learning. By linking together many different nodes, each one responsible for a simple computation, neural networks attempt to form a rough parallel to the way that neurons function in the human brain.


The idea behind neural networks was first born in the 1950s with the perceptron algorithm. A perceptron is a simplified model of a human neuron that accepts an input and performs a computation on that input. The output is then fed to an activation function, which decides whether the neuron will “fire” based on the output value.


While one perceptron cannot recognize complicated patterns on its own, there are thousands, millions, or even billions of connections between the neurons in a neural network. This allows the network to handle even highly complex inputs.


Researchers “train” a neural network over time by analyzing its outputs on different problems and comparing them with the correct answers. Using an algorithm known as backpropagation, the neural network can adjust the influence of any particular node in the network, attempting to reduce the errors that the network makes when calculating a final result.

.


https://www.verypossible.com/insights/machine-learning-vs.-neural-networks


Wednesday, August 8, 2018

ML5JS vs KERAS



 .

.

.

https://towardsdatascience.com/introduction-to-ml5-js-3fe51d6a4661

.

Wednesday, May 9, 2018

AFINN-based sentiment analysis for Node.js

 .

AFINN-based sentiment analysis for Node.js

Build Status Coverage Status Greenkeeper badge

Sentiment is a Node.js module that uses the AFINN-165 wordlist and Emoji Sentiment Ranking to perform sentiment analysis on arbitrary blocks of input text. Sentiment provides several things:

  • Performance (see benchmarks below)
  • The ability to append and overwrite word / value pairs from the AFINN wordlist
  • A build process that makes updating sentiment to future wordlists trivial

Installation

npm install sentiment

Usage

var sentiment = require('sentiment');

var r1 = sentiment('Cats are stupid.');
console.dir(r1);        // Score: -2, Comparative: -0.666

var r2 = sentiment('Cats are totally amazing!');
console.dir(r2);        // Score: 4, Comparative: 1

Adding / overwriting words

You can append and/or overwrite values from AFINN by simply injecting key/value pairs into a sentiment method call:

var sentiment = require('sentiment');

var result = sentiment('Cats are totally amazing!', {
    'cats': 5,
    'amazing': 2  
});
console.dir(result);    // Score: 7, Comparative: 1.75

How it works

AFINN

AFINN is a list of words rated for valence with an integer between minus five (negative) and plus five (positive). Sentiment analysis is performed by cross-checking the string tokens(words, emojis) with the AFINN list and getting their respective scores. The comparative score is simply: sum of each token / number of tokens. So for example let's take the following:

I love cats, but I am allergic to them.

That string results in the following:

{
    score: 1,
    comparative: 0.1111111111111111,
    tokens: [
        'i',
        'love',
        'cats',
        'but',
        'i',
        'am',
        'allergic',
        'to',
        'them'
    ],
    words: [
        'allergic',
        'love'
    ],
    positive: [
        'love'
    ],
    negative: [
        'allergic'
    ]
}
  • Returned Objects
    • Score: Score calculated by adding the sentiment values of recongnized words.
    • Comparative: Comparative score of the input string.
    • Token: All the tokens like words or emojis found in the input string.
    • Words: List of words from input string that were found in AFINN list.
    • Positive: List of postive words in input string that were found in AFINN list.
    • Negative: List of negative words in input string that were found in AFINN list.

In this case, love has a value of 3, allergic has a value of -2, and the remaining tokens are neutral with a value of 0. Because the string has 9 tokens the resulting comparative score looks like: (3 + -2) / 9 = 0.111111111

This approach leaves you with a mid-point of 0 and the upper and lower bounds are constrained to positive and negative 5 respectively (the same as each token! ðŸ˜¸). For example, let's imagine an incredibly "positive" string with 200 tokens and where each token has an AFINN score of 5. Our resulting comparative score would look like this:

(max positive score * number of tokens) / number of tokens
(5 * 200) / 200 = 5

Tokenization

Tokenization works by splitting the lines of input string, then removing the special characters, and finally splitting it using spaces. This is used to get list of words in the string.


Benchmarks

A primary motivation for designing sentiment was performance. As such, it includes a benchmark script within the test directory that compares it against the Sentimental module which provides a nearly equivalent interface and approach. Based on these benchmarks, running on a MacBook Pro with Node v6.9.1, sentiment is twice as fast as alternative implementations:

sentiment (Latest) x 448,788 ops/sec ±1.02% (88 runs sampled)
Sentimental (1.0.1) x 240,103 ops/sec ±5.13% (81 runs sampled)

To run the benchmarks yourself:

make benchmark

Validation

While the accuracy provided by AFINN is quite good considering it's computational performance (see above) there is always room for improvement. Therefore the sentiment module is open to accepting PRs which modify or amend the AFINN / Emoji datasets or implementation given that they improve accuracy and maintain similar performance characteristics. In order to establish this, we test the sentiment module against three labelled datasets provided by UCI.

To run the validation tests yourself:

make validate

Rand Accuracy (AFINN Only)

Amazon:  0.70
IMDB:    0.76
Yelp:    0.67

Rand Accuracy (AFINN + Additions)

Amazon:  0.72 (+2%)
IMDB:    0.76 (+0%)
Yelp:    0.69 (+2%)

Testing

npm test

.

https://www.npmjs.com/package/@trainorpj/sentiment

.

https://unpkg.com/@trainorpj/sentiment@4.1.4/bundle/bundle.js


Friday, April 6, 2018

ObservableHq Tutorial: An Interactive Introduction to TensorFlow.js

 


.

1) Import the TensorFlow.js

2) Import A helper method to show the tensor array

3) Create a model that is used to predict the MNIST dataset. The module constitutes two conv layers two pooling layers and a dense layer. Compile the model using an adam optimizer.

4) Load a pretrained model called mobilenet.

5) Load the image classes.

6) Predict image class.

6.1) Preprocess the image by converting it to a tensor then normalize,

6.2) Predict based on the given model classes

.

https://observablehq.com/@zaidalyafeai/an-intractive-introduction-to-tensorflow-js

.

Alternative:

https://observablehq.com/d/95a9b4e931cccfb0

,

Tuesday, January 30, 2018

ObservableHq Tutorial: Introduction to Data (JavaScript ML Notebook Alternative To Python ML Jupyter Notebook)

.

Introduction to Data

How do you get data into Observable for analysis and visualization? Depending on its form and where it lives, there are a variety of ways:

  • inline - embedded in the notebook as code, for small amounts of data
  • files - attached to the notebook, for medium amounts of data (e.g., CSV, SQLite)
  • APIs - queried from a remote server, for programmatic access to data
  • databases - via an Observable database client, for accessing SQL databases

You can also download generated data from notebooks.

.

https://observablehq.com/@observablehq/introduction-to-data

.

SQLite

Observable has built-in support for SQLite, “a small, fast, self-contained, high-reliability, full-featured, SQL database engine” and “the most used database engine in the world.” Observable’s SQLite client uses sql.js, an Emscripten port of SQLite.

After attaching a SQLite file to your notebook, create a SQLite database client by calling file.sqlite().

.

https://observablehq.com/@observablehq/sqlite

.