Hello reader,
I’m getting the following error while running the code for iris classifier:
The code that create the error is :
<html>
<head></head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
<script lang="js">
async function run(){
const csvUrl = "file://C:/Users/ayyap/Desktop/tensorflow-2-public-main/tensorflow-2-public-main/C1_Browser-based-TF-JS/W1/ungraded_labs/data/iris.csv";
const trainingData = tf.data.csv(
csvUrl,
{
columnConfigs: {
sepalLength: {
type: 'float32'
},
sepalWidth: {
type: 'float32'
},
petalLength: {
type: 'float32'
},
petalWidth: {
type: 'float32'
},
species: {
type: 'string',
isLabel:true
}
}
}
// {
// columnConfigs: {
// species: {
// isLabel: true
// }
// }
// }
);
const numOfFeatures = (await trainingData.columnNames()).length-1;
const numOfSamples = 150;
const convertedData =
trainingData.map(({xs,ys})=>{
const labels = [
ys.species == "setosa" ? 1: 0,
ys.species == "virginica"?1:0,
ys.species == "versicolor"?1:0
]
return {xs:Object.values(xs),ys:Object.values(labels)};
}).batch(10);
const model = tf.sequential();
model.add(tf.layers.dense({inputShape: [numOfFeatures], activation: "sigmoid", units: 5}));
model.add(tf.layers.dense({acivation: "softmax", units: 3}));
model.compile({loss: "categoricalCrossentropy", optimizer: tf.train.adam(0.06)});
await model.fitDataset(
convertedData,
{
epochs: 100,
callbacks: {
onEpochEnd: async(epoch,logs) => {
console.log("Epoch: "+epoch+"Loss: "+logs.loss);
}
}
}
);
const testVal = tf.tensor2d([4.4,2.9,1.4,0.2],[1,4]);
const prediction = model.predict(testVal);
alert(prediction)
}
run();
</script>
</html>
When I try to use the webserver, it is showing as outdated and also without using file:// it is throwing server responded 404 file not found!. Now that error is gone and the new error above is coming. Please help. Thanks in advance.