Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update C1_W1_Assignment.html #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions C1_Browser-based-TF-JS/W1/assignment/C1_W1_Assignment.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@
// 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: {
species: {
isLabel: true
}
}
// YOUR CODE HERE

});

// Convert the training data into arrays in the space below.
// Note: In this case, the labels are integers, not strings.
// 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}) => {
const labels = [
ys.species == "malignant" ? 1:0,
ys.species == "benign" ? 1:0
]
return{ xs:Object.values(xs), ys:Object.values(labels)};
}).batch(10);
// YOUR CODE HERE

const testingUrl = '/data/wdbc-test.csv';

Expand All @@ -30,23 +40,31 @@
// 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: {
species: {
isLabel : true
}
}
});

// Convert the testing data into arrays in the space below.
// Note: In this case, the labels are integers, not strings.
// 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}) => {
const labels = [
ys.species == "malignant" ? 1:0,
ys.species == "benign" ? 1:0
]
return { xs:Obhect.values(xs), ys:Object.values(labels)};
}).batch(10);// 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.columnNames()).length - 1; // YOUR CODE HERE


// In the space below create a neural network that predicts 1 if the diagnosis is malignant
Expand All @@ -58,14 +76,12 @@
// 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],activation="relu", units:10}))
model.add(tf.layers.dense({activation:"sigmoid", units : 2}));
// 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(loss:"binarycrossentropy", optimizer:tf.train.adam(0.0612)});// YOUR CODE HERE);


await model.fitDataset(convertedTrainingData,
Expand All @@ -82,4 +98,4 @@
</script>
<body>
</body>
</html>
</html>