This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../core-icon-button/core-icon-button.html"> | |
<link rel="import" href="../core-toolbar/core-toolbar.html"> | |
<link rel="import" href="../core-icons/core-icons.html"> | |
<link rel="import" href="../core-icon/core-icon.html"> | |
<link rel="import" href="../core-input/core-input.html"> | |
<link rel="import" href="../topeka-elements/category-images.html"> | |
<link rel="import" href="../core-icons/av-icons.html"> | |
<link rel="import" href="../paper-fab/paper-fab.html"> | |
<polymer-element name="uiapp"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function performRegression() { | |
regressionModel = new SLR(X, y); // Train the model on training data | |
console.log(regressionModel.toString(3)); | |
predictOutput(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); // For user prompt to allow predictions | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ml = require('ml-regression'); | |
const csv = require('csvtojson'); | |
const SLR = ml.SLR; // Simple Linear Regression | |
const csvFilePath = 'advertising.csv'; // Data | |
let csvData = [], // parsed Data | |
X = [], // Input | |
y = []; // Output | |
let regressionModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function predictOutput() { | |
rl.question('Enter input X for prediction (Press CTRL+C to exit) : ', (answer) => { | |
console.log(`At X = ${answer}, y = ${regressionModel.predict(parseFloat(answer))}`); | |
predictOutput(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dressData() { | |
/** | |
* One row of the data object looks like: | |
* { | |
* TV: "10", | |
* Radio: "100", | |
* Newspaper: "20", | |
* "Sales": "1000" | |
* } | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
csv() | |
.fromFile(csvFilePath) | |
.on('json', (jsonObj) => { | |
csvData.push(jsonObj); | |
}) | |
.on('done', () => { | |
dressData(); // To get data points from JSON Objects | |
performRegression(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ml = require('ml-regression'); | |
const csv = require('csvtojson'); | |
const SLR = ml.SLR; // Simple Linear Regression | |
const csvFilePath = 'advertising.csv'; // Data | |
let csvData = [], // parsed Data | |
X = [], // Input | |
y = []; // Output | |
let regressionModel; |
OlderNewer