-
-
Save learncodeacademy/a96d80a29538c7625652493c2407b6be to your computer and use it in GitHub Desktop.
import * as tf from "@tensorflow/tfjs" | |
import "@tensorflow/tfjs-node" | |
import iris from "./iris.json" | |
import irisTesting from "./iris-testing.json" | |
// convert/setup our data | |
const trainingData = tf.tensor2d(iris.map(item => [ | |
item.sepal_length, item.sepal_width, item.petal_length, item.petal_width, | |
])) | |
const outputData = tf.tensor2d(iris.map(item => [ | |
item.species === "setosa" ? 1 : 0, | |
item.species === "virginica" ? 1 : 0, | |
item.species === "versicolor" ? 1 : 0, | |
])) | |
const testingData = tf.tensor2d(irisTesting.map(item => [ | |
item.sepal_length, item.sepal_width, item.petal_length, item.petal_width, | |
])) | |
// build neural network | |
const model = tf.sequential() | |
model.add(tf.layers.dense({ | |
inputShape: [4], | |
activation: "sigmoid", | |
units: 5, | |
})) | |
model.add(tf.layers.dense({ | |
inputShape: [5], | |
activation: "sigmoid", | |
units: 3, | |
})) | |
model.add(tf.layers.dense({ | |
activation: "sigmoid", | |
units: 3, | |
})) | |
model.compile({ | |
loss: "meanSquaredError", | |
optimizer: tf.train.adam(.06), | |
}) | |
// train/fit our network | |
const startTime = Date.now() | |
model.fit(trainingData, outputData, {epochs: 100}) | |
.then((history) => { | |
// console.log(history) | |
model.predict(testingData).print() | |
}) | |
// test network |
[ | |
{ | |
"sepal_length": 5.4, | |
"sepal_width": 3.9, | |
"petal_length": 1.7, | |
"petal_width": 0.4, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.9, | |
"sepal_width": 3, | |
"petal_length": 5.1, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 2.9, | |
"petal_length": 4.2, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
} | |
] |
[ | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.5, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.9, | |
"sepal_width": 3, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.7, | |
"sepal_width": 3.2, | |
"petal_length": 1.3, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.6, | |
"sepal_width": 3.1, | |
"petal_length": 1.5, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3.6, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.6, | |
"sepal_width": 3.4, | |
"petal_length": 1.4, | |
"petal_width": 0.3, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3.4, | |
"petal_length": 1.5, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.4, | |
"sepal_width": 2.9, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.9, | |
"sepal_width": 3.1, | |
"petal_length": 1.5, | |
"petal_width": 0.1, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.4, | |
"sepal_width": 3.7, | |
"petal_length": 1.5, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.8, | |
"sepal_width": 3.4, | |
"petal_length": 1.6, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.8, | |
"sepal_width": 3, | |
"petal_length": 1.4, | |
"petal_width": 0.1, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.3, | |
"sepal_width": 3, | |
"petal_length": 1.1, | |
"petal_width": 0.1, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.8, | |
"sepal_width": 4, | |
"petal_length": 1.2, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 4.4, | |
"petal_length": 1.5, | |
"petal_width": 0.4, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.4, | |
"sepal_width": 3.9, | |
"petal_length": 1.3, | |
"petal_width": 0.4, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.5, | |
"petal_length": 1.4, | |
"petal_width": 0.3, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 3.8, | |
"petal_length": 1.7, | |
"petal_width": 0.3, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.8, | |
"petal_length": 1.5, | |
"petal_width": 0.3, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.4, | |
"sepal_width": 3.4, | |
"petal_length": 1.7, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.7, | |
"petal_length": 1.5, | |
"petal_width": 0.4, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.6, | |
"sepal_width": 3.6, | |
"petal_length": 1, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.3, | |
"petal_length": 1.7, | |
"petal_width": 0.5, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.8, | |
"sepal_width": 3.4, | |
"petal_length": 1.9, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3, | |
"petal_length": 1.6, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3.4, | |
"petal_length": 1.6, | |
"petal_width": 0.4, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.2, | |
"sepal_width": 3.5, | |
"petal_length": 1.5, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.2, | |
"sepal_width": 3.4, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.7, | |
"sepal_width": 3.2, | |
"petal_length": 1.6, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.8, | |
"sepal_width": 3.1, | |
"petal_length": 1.6, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.4, | |
"sepal_width": 3.4, | |
"petal_length": 1.5, | |
"petal_width": 0.4, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.2, | |
"sepal_width": 4.1, | |
"petal_length": 1.5, | |
"petal_width": 0.1, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.5, | |
"sepal_width": 4.2, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.9, | |
"sepal_width": 3.1, | |
"petal_length": 1.5, | |
"petal_width": 0.1, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3.2, | |
"petal_length": 1.2, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.5, | |
"sepal_width": 3.5, | |
"petal_length": 1.3, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.9, | |
"sepal_width": 3.1, | |
"petal_length": 1.5, | |
"petal_width": 0.1, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.4, | |
"sepal_width": 3, | |
"petal_length": 1.3, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.4, | |
"petal_length": 1.5, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3.5, | |
"petal_length": 1.3, | |
"petal_width": 0.3, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.5, | |
"sepal_width": 2.3, | |
"petal_length": 1.3, | |
"petal_width": 0.3, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.4, | |
"sepal_width": 3.2, | |
"petal_length": 1.3, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3.5, | |
"petal_length": 1.6, | |
"petal_width": 0.6, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.8, | |
"petal_length": 1.9, | |
"petal_width": 0.4, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.8, | |
"sepal_width": 3, | |
"petal_length": 1.4, | |
"petal_width": 0.3, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 3.8, | |
"petal_length": 1.6, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 4.6, | |
"sepal_width": 3.2, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5.3, | |
"sepal_width": 3.7, | |
"petal_length": 1.5, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 3.3, | |
"petal_length": 1.4, | |
"petal_width": 0.2, | |
"species": "setosa" | |
}, | |
{ | |
"sepal_length": 7, | |
"sepal_width": 3.2, | |
"petal_length": 4.7, | |
"petal_width": 1.4, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.4, | |
"sepal_width": 3.2, | |
"petal_length": 4.5, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.9, | |
"sepal_width": 3.1, | |
"petal_length": 4.9, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.5, | |
"sepal_width": 2.3, | |
"petal_length": 4, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.5, | |
"sepal_width": 2.8, | |
"petal_length": 4.6, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 2.8, | |
"petal_length": 4.5, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 3.3, | |
"petal_length": 4.7, | |
"petal_width": 1.6, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 4.9, | |
"sepal_width": 2.4, | |
"petal_length": 3.3, | |
"petal_width": 1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.6, | |
"sepal_width": 2.9, | |
"petal_length": 4.6, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.2, | |
"sepal_width": 2.7, | |
"petal_length": 3.9, | |
"petal_width": 1.4, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 2, | |
"petal_length": 3.5, | |
"petal_width": 1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.9, | |
"sepal_width": 3, | |
"petal_length": 4.2, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6, | |
"sepal_width": 2.2, | |
"petal_length": 4, | |
"petal_width": 1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.1, | |
"sepal_width": 2.9, | |
"petal_length": 4.7, | |
"petal_width": 1.4, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.6, | |
"sepal_width": 2.9, | |
"petal_length": 3.6, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 3.1, | |
"petal_length": 4.4, | |
"petal_width": 1.4, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.6, | |
"sepal_width": 3, | |
"petal_length": 4.5, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.8, | |
"sepal_width": 2.7, | |
"petal_length": 4.1, | |
"petal_width": 1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.2, | |
"sepal_width": 2.2, | |
"petal_length": 4.5, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.6, | |
"sepal_width": 2.5, | |
"petal_length": 3.9, | |
"petal_width": 1.1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.9, | |
"sepal_width": 3.2, | |
"petal_length": 4.8, | |
"petal_width": 1.8, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.1, | |
"sepal_width": 2.8, | |
"petal_length": 4, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 2.5, | |
"petal_length": 4.9, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.1, | |
"sepal_width": 2.8, | |
"petal_length": 4.7, | |
"petal_width": 1.2, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.4, | |
"sepal_width": 2.9, | |
"petal_length": 4.3, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.6, | |
"sepal_width": 3, | |
"petal_length": 4.4, | |
"petal_width": 1.4, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.8, | |
"sepal_width": 2.8, | |
"petal_length": 4.8, | |
"petal_width": 1.4, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 3, | |
"petal_length": 5, | |
"petal_width": 1.7, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6, | |
"sepal_width": 2.9, | |
"petal_length": 4.5, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 2.6, | |
"petal_length": 3.5, | |
"petal_width": 1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.5, | |
"sepal_width": 2.4, | |
"petal_length": 3.8, | |
"petal_width": 1.1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.5, | |
"sepal_width": 2.4, | |
"petal_length": 3.7, | |
"petal_width": 1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.8, | |
"sepal_width": 2.7, | |
"petal_length": 3.9, | |
"petal_width": 1.2, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6, | |
"sepal_width": 2.7, | |
"petal_length": 5.1, | |
"petal_width": 1.6, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.4, | |
"sepal_width": 3, | |
"petal_length": 4.5, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6, | |
"sepal_width": 3.4, | |
"petal_length": 4.5, | |
"petal_width": 1.6, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 3.1, | |
"petal_length": 4.7, | |
"petal_width": 1.5, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 2.3, | |
"petal_length": 4.4, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.6, | |
"sepal_width": 3, | |
"petal_length": 4.1, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.5, | |
"sepal_width": 2.5, | |
"petal_length": 4, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.5, | |
"sepal_width": 2.6, | |
"petal_length": 4.4, | |
"petal_width": 1.2, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.1, | |
"sepal_width": 3, | |
"petal_length": 4.6, | |
"petal_width": 1.4, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.8, | |
"sepal_width": 2.6, | |
"petal_length": 4, | |
"petal_width": 1.2, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5, | |
"sepal_width": 2.3, | |
"petal_length": 3.3, | |
"petal_width": 1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.6, | |
"sepal_width": 2.7, | |
"petal_length": 4.2, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 3, | |
"petal_length": 4.2, | |
"petal_width": 1.2, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.2, | |
"sepal_width": 2.9, | |
"petal_length": 4.3, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.1, | |
"sepal_width": 2.5, | |
"petal_length": 3, | |
"petal_width": 1.1, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 2.8, | |
"petal_length": 4.1, | |
"petal_width": 1.3, | |
"species": "versicolor" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 3.3, | |
"petal_length": 6, | |
"petal_width": 2.5, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 5.8, | |
"sepal_width": 2.7, | |
"petal_length": 5.1, | |
"petal_width": 1.9, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.1, | |
"sepal_width": 3, | |
"petal_length": 5.9, | |
"petal_width": 2.1, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 2.9, | |
"petal_length": 5.6, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.5, | |
"sepal_width": 3, | |
"petal_length": 5.8, | |
"petal_width": 2.2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.6, | |
"sepal_width": 3, | |
"petal_length": 6.6, | |
"petal_width": 2.1, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 4.9, | |
"sepal_width": 2.5, | |
"petal_length": 4.5, | |
"petal_width": 1.7, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.3, | |
"sepal_width": 2.9, | |
"petal_length": 6.3, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 2.5, | |
"petal_length": 5.8, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.2, | |
"sepal_width": 3.6, | |
"petal_length": 6.1, | |
"petal_width": 2.5, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.5, | |
"sepal_width": 3.2, | |
"petal_length": 5.1, | |
"petal_width": 2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.4, | |
"sepal_width": 2.7, | |
"petal_length": 5.3, | |
"petal_width": 1.9, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.8, | |
"sepal_width": 3, | |
"petal_length": 5.5, | |
"petal_width": 2.1, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 5.7, | |
"sepal_width": 2.5, | |
"petal_length": 5, | |
"petal_width": 2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 5.8, | |
"sepal_width": 2.8, | |
"petal_length": 5.1, | |
"petal_width": 2.4, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.4, | |
"sepal_width": 3.2, | |
"petal_length": 5.3, | |
"petal_width": 2.3, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.5, | |
"sepal_width": 3, | |
"petal_length": 5.5, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.7, | |
"sepal_width": 3.8, | |
"petal_length": 6.7, | |
"petal_width": 2.2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.7, | |
"sepal_width": 2.6, | |
"petal_length": 6.9, | |
"petal_width": 2.3, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6, | |
"sepal_width": 2.2, | |
"petal_length": 5, | |
"petal_width": 1.5, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.9, | |
"sepal_width": 3.2, | |
"petal_length": 5.7, | |
"petal_width": 2.3, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 5.6, | |
"sepal_width": 2.8, | |
"petal_length": 4.9, | |
"petal_width": 2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.7, | |
"sepal_width": 2.8, | |
"petal_length": 6.7, | |
"petal_width": 2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 2.7, | |
"petal_length": 4.9, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 3.3, | |
"petal_length": 5.7, | |
"petal_width": 2.1, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.2, | |
"sepal_width": 3.2, | |
"petal_length": 6, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.2, | |
"sepal_width": 2.8, | |
"petal_length": 4.8, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.1, | |
"sepal_width": 3, | |
"petal_length": 4.9, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.4, | |
"sepal_width": 2.8, | |
"petal_length": 5.6, | |
"petal_width": 2.1, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.2, | |
"sepal_width": 3, | |
"petal_length": 5.8, | |
"petal_width": 1.6, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.4, | |
"sepal_width": 2.8, | |
"petal_length": 6.1, | |
"petal_width": 1.9, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.9, | |
"sepal_width": 3.8, | |
"petal_length": 6.4, | |
"petal_width": 2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.4, | |
"sepal_width": 2.8, | |
"petal_length": 5.6, | |
"petal_width": 2.2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 2.8, | |
"petal_length": 5.1, | |
"petal_width": 1.5, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.1, | |
"sepal_width": 2.6, | |
"petal_length": 5.6, | |
"petal_width": 1.4, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 7.7, | |
"sepal_width": 3, | |
"petal_length": 6.1, | |
"petal_width": 2.3, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 3.4, | |
"petal_length": 5.6, | |
"petal_width": 2.4, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.4, | |
"sepal_width": 3.1, | |
"petal_length": 5.5, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6, | |
"sepal_width": 3, | |
"petal_length": 4.8, | |
"petal_width": 1.8, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.9, | |
"sepal_width": 3.1, | |
"petal_length": 5.4, | |
"petal_width": 2.1, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 3.1, | |
"petal_length": 5.6, | |
"petal_width": 2.4, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.9, | |
"sepal_width": 3.1, | |
"petal_length": 5.1, | |
"petal_width": 2.3, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 5.8, | |
"sepal_width": 2.7, | |
"petal_length": 5.1, | |
"petal_width": 1.9, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.8, | |
"sepal_width": 3.2, | |
"petal_length": 5.9, | |
"petal_width": 2.3, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 3.3, | |
"petal_length": 5.7, | |
"petal_width": 2.5, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.7, | |
"sepal_width": 3, | |
"petal_length": 5.2, | |
"petal_width": 2.3, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.3, | |
"sepal_width": 2.5, | |
"petal_length": 5, | |
"petal_width": 1.9, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.5, | |
"sepal_width": 3, | |
"petal_length": 5.2, | |
"petal_width": 2, | |
"species": "virginica" | |
}, | |
{ | |
"sepal_length": 6.2, | |
"sepal_width": 3.4, | |
"petal_length": 5.4, | |
"petal_width": 2.3, | |
"species": "virginica" | |
} | |
] |
{ | |
"name": "tfjs", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "parcel --target=node iris.js & nodemon dist/iris.js" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"@tensorflow/tfjs": "^0.11.6", | |
"@tensorflow/tfjs-node": "^0.1.7", | |
"nodemon": "^1.17.5", | |
"parcel": "^1.9.0" | |
} | |
} |
Hi kzhangkzhang!
I don't think that it is supported on Windows platform yet.
I do not know if this is something to look into but, I was looking at this other tutorial and I was able to run the app via npm without a problem:
Perhaps he is using a different npm package: https://www.npmjs.com/package/@tensorflow/tfjs
https://github.com/llSourcell/Financial_Forecasting_with_TensorflowJS
https://www.youtube.com/watch?v=5Uw1iSwvHH8
Thanks,
Lars
hi, i wanted to ask regarding this model,
Des this model works on data that consist of unclassified data?
for example, i tried to create the neural network from on my PCA(Principal Component Analysis) data. however, the result of my PCA data only consists of numbers that based on how many PC i used after i ranked it by based their variance. how i add it into this type of model?
thank you
Hello. Thanks a lot for this example, it helped me a lot.
I'm still new to tfjs and I'm still struggling with 1 thing and was hoping if you could help.
in file iris-tensorflow-js.js line 16 , what if, for example, sepal_length is of type String and not an integer?
thanks in advance
I am using Windows 10 with node v8.9.4. I duplicated package.json like yours, then issue 'npm install' and I got bunch of errors:
$ npm install
win32-x64-node-8
exists; testingBinary is fine; exiting
F>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp: Undefined variable tensorflow-library-target in binding.gyp while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error:
gyp
failed with exit code: 1gyp ERR! stack at ChildProcess.onCpExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:336:16)
Do you know why I am getting such error?
Thanks!
Kevin