From 159951aceee4b67766855c4689fb59abe1d8a3b5 Mon Sep 17 00:00:00 2001 From: sulisindriyani Date: Thu, 7 Nov 2024 23:36:53 +0700 Subject: [PATCH 1/4] Update C1_W1_Assignment.html --- .../W1/assignment/C1_W1_Assignment.html | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 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..72541863 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,9 +11,11 @@ // 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, { - - // YOUR CODE HERE - + columnConfigs: { + diagnosis: { + isLabel: true + } + } }); // Convert the training data into arrays in the space below. @@ -21,7 +23,9 @@ // 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(10); const testingUrl = '/data/wdbc-test.csv'; @@ -30,8 +34,11 @@ // 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, { - - // YOUR CODE HERE + columnConfigs: { + diagnosis: { + isLabel: true + } + } }); @@ -40,13 +47,14 @@ // 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(10); // 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.columnNames()).length - 1; // In the space below create a neural network that predicts 1 if the diagnosis is malignant @@ -58,15 +66,18 @@ // 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(); - - // YOUR CODE HERE - + model.add(tf.layers.dense({inputShape: [numOfFeatures], units: 50, activation: 'relu'})); + model.add(tf.layers.dense({units: 50, activation: 'relu'})); + model.add(tf.layers.dense({units: 1, activation: 'sigmoid'})); // Compile the model using the binaryCrossentropy loss, // the rmsprop optimizer, and accuracy for your metrics. - model.compile(// YOUR CODE HERE); - + model.compile({ + optimizer: 'rmsprop', + loss: 'binaryCrossentropy', + metrics: ['accuracy'] + }); await model.fitDataset(convertedTrainingData, {epochs:100, @@ -82,4 +93,4 @@ - \ No newline at end of file + From 8d4ca61ea7e015c3ed65371285e93f9559882e91 Mon Sep 17 00:00:00 2001 From: sulisindriyani Date: Fri, 8 Nov 2024 11:06:03 +0700 Subject: [PATCH 2/4] Update C1_W1_Assignment.html --- C1_Browser-based-TF-JS/W1/assignment/C1_W1_Assignment.html | 4 ++-- 1 file changed, 2 insertions(+), 2 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 72541863..0fe23aa0 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 @@ -4,7 +4,7 @@