Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/finnp/feature-scaling
Scale the values of an array or stream of objects within [0,1]
https://github.com/finnp/feature-scaling
Last synced: 14 days ago
JSON representation
Scale the values of an array or stream of objects within [0,1]
- Host: GitHub
- URL: https://github.com/finnp/feature-scaling
- Owner: finnp
- Created: 2014-09-22T20:21:57.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-22T21:22:36.000Z (about 10 years ago)
- Last Synced: 2024-10-17T02:36:02.154Z (28 days ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# feature-scaling
This module allows you to [feature scale](http://en.wikipedia.org/wiki/Feature_scaling)
an array of objects with numeric values.You can install it with `npm install feature-scaling` or instead use the
`-g` flag to install the global CLI.For the objects it will treat the properties of the objects as stochastic
variables. And project them with this formular:```
x' = (x-min(X)) / (max(X) - min(X))
```Values of the objects, that are not parseable as numbers will be ignored.
## Example
```js
var normalize = require('feature-scaling')var data = [
{a: 1, b:1},
{a: "2", b:"1", note: "special"},
{a: 3, b:10}
]var normalized = normalize(data)
// normalized will be
// [ { a: 0, b: 0 },
// { a: 0.5, b: 0, note: 'special' },
// { a: 1, b: 1 }
// ]
```## CLI usage
Just pipe in new line delimited JSON into `feature-scaling` command and it will return
the data normalized. Note that this will load your entire input into memory. If
this is an issue for you open an issue on this repo :).Given `data.ldjson`:
```
{"a": 1, "b":1}
{"a": 2, "b":1}
{"a": 3, "b":10}
```This will output the following:
```
$ feature-scaling < data.ldjson
{"a":0,"b":0}
{"a":0.5,"b":0}
{"a":1,"b":1}
```