From 96f97512fffbd2ea5e65d1de32d743a29de95522 Mon Sep 17 00:00:00 2001 From: anisaanada-ML Date: Wed, 20 Nov 2024 18:37:34 +0700 Subject: [PATCH] Update C1_W1_Assignment.html --- .../W1/assignment/C1_W1_Assignment.html | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/C1_Browser-based-TF-JS/W1/assignment/C1_W1_Assignment.html b/C1_Browser-based-TF-JS/W1/assignment/C1_W1_Assignment.html index 023c6143..9598eafa 100755 --- a/C1_Browser-based-TF-JS/W1/assignment/C1_W1_Assignment.html +++ b/C1_Browser-based-TF-JS/W1/assignment/C1_W1_Assignment.html @@ -11,7 +11,9 @@ // HINT: Remember that you are trying to build a classifier that // can predict from the data whether the diagnosis is malignant or benign. const trainingData = tf.data.csv(trainingUrl, { - + columnConfigs: { + diagnosis: { isLabel: true } // Kolom 'diagnosis' sebagai label + } // YOUR CODE HERE }); @@ -21,7 +23,13 @@ // Therefore, there is no need to convert string labels into // a one-hot encoded array of label values like we did in the // Iris dataset example. - const convertedTrainingData = // YOUR CODE HERE + const convertedTrainingData = trainingData.map(({ xs, ys }) => { + return { + xs: Object.values(xs), + ys: Object.values(ys) + }; + }).batch(32); + // YOUR CODE HERE const testingUrl = '/data/wdbc-test.csv'; @@ -30,7 +38,9 @@ // HINT: Remember that you are trying to build a classifier that // can predict from the data whether the diagnosis is malignant or benign. const testingData = tf.data.csv(testingUrl, { - + columnConfigs: { + diagnosis: { isLabel: true } // Kolom 'diagnosis' sebagai label + } // YOUR CODE HERE }); @@ -40,13 +50,19 @@ // Therefore, there is no need to convert string labels into // a one-hot encoded array of label values like we did in the // Iris dataset example. - const convertedTestingData = // YOUR CODE HERE + const convertedTestingData = testingData.map(({ xs, ys }) => { + return { + xs: Object.values(xs), + ys: Object.values(ys) + }; + }).batch(32); + // YOUR CODE HERE // Specify the number of features in the space below. // HINT: You can get the number of features from the number of columns // and the number of labels in the training data. - const numOfFeatures = // YOUR CODE HERE + const numOfFeatures = (await trainingData.take(1).toArray())[0].xs.length; // YOUR CODE HERE // In the space below create a neural network that predicts 1 if the diagnosis is malignant @@ -58,14 +74,24 @@ // using ReLu activation functions where applicable. For this dataset only a few // hidden layers should be enough to get a high accuracy. const model = tf.sequential(); - + model.add(tf.layers.dense({ inputShape: [numOfFeatures], units: 16, activation: 'relu' })); + + // Hidden layers + model.add(tf.layers.dense({ units: 8, activation: 'relu' })); + + // Output layer + model.add(tf.layers.dense({ units: 1, activation: 'sigmoid' })); // YOUR CODE HERE // Compile the model using the binaryCrossentropy loss, // the rmsprop optimizer, and accuracy for your metrics. - model.compile(// YOUR CODE HERE); + model.compile({ + optimizer: tf.train.rmsprop(), + loss: 'binaryCrossentropy', + metrics: ['accuracy'] + }); await model.fitDataset(convertedTrainingData, @@ -82,4 +108,4 @@ - \ No newline at end of file +