-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlisting-5.10.js
More file actions
23 lines (21 loc) · 896 Bytes
/
listing-5.10.js
File metadata and controls
23 lines (21 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"use strict";
const dataForge = require('data-forge');
const formulajs = require('formulajs');
dataForge.readFile("./data/monthly_crashes-cut-down.csv")
.parseCSV()
.then(dataFrame => {
dataFrame = dataFrame.parseFloats([
"Month#", "Year", "Crashes", "Fatalities",
"Hospitalized"
]);
const monthNoSeries = dataFrame.getSeries("Month#");
const xValues = monthNoSeries.head(6).toArray();
const fatalitiesSeries = dataFrame.getSeries("Fatalities");
const yValues = fatalitiesSeries.head(6).toArray();
const nextMonthNo = monthNoSeries.skip(6).first();
const nextMonthFatalitiesForecast = formulajs.FORECAST(nextMonthNo, yValues, xValues);
console.log('Forecasted fatalities: ' + nextMonthFatalitiesForecast);
})
.catch(err => {
console.error(err && err.stack || err);
});