Created
September 6, 2018 20:57
-
-
Save kmaher9/bb2b244697e6c3ec96d86d390109ae46 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // load each line of the training data into a new index of an array | |
| var trainingFile = fs.readFileSync("data.csv").toString().split("\n") | |
| // iterate over each line of the training data, adding it to a new array for training later | |
| for (var i = 0; i < trainingFile.length; i++) { | |
| var entry = trainingFile[i] | |
| var values = entry.split(",") | |
| var points = [parseFloat(values[0]), parseFloat(values[1]), parseFloat(values[2]), parseFloat(values[3])] | |
| if (i <= 49) { | |
| trainingData.push({input: points, output: {setosa: 1}}) | |
| } | |
| else if (i > 49 && i <= 99) { | |
| trainingData.push({input: points, output: {versicolor: 1}}) | |
| } | |
| else if (i > 99 && i <= 149) { | |
| trainingData.push({input: points, output: {virginica: 1}}) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment