Skip to content

Instantly share code, notes, and snippets.

@kmaher9
Created September 6, 2018 20:57
Show Gist options
  • Select an option

  • Save kmaher9/bb2b244697e6c3ec96d86d390109ae46 to your computer and use it in GitHub Desktop.

Select an option

Save kmaher9/bb2b244697e6c3ec96d86d390109ae46 to your computer and use it in GitHub Desktop.
// 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