SlideShare a Scribd company logo
Please help fill in the missing code below in order for it run correctly. Areas that are
needed/missing are in highlighted in bold .
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
#1) Generate the synthetic data using the following Python code snippet.
# Generate synthetic data
N = 100
# Zeros form a Gaussian centered at (-1, -1)
x_zeros = np.random.multivariate_normal(mean=np.array((-1, -1)), cov=.1*np.eye(2),
size=(N//2,))
y_zeros = np.zeros((N//2,))
# Ones form a Gaussian centered at (1, 1)
x_ones = np.random.multivariate_normal(mean=np.array((1, 1)), cov=.1*np.eye(2),
size=(N//2,))
y_ones = np.ones((N//2,))
x_np = np.vstack([x_zeros, x_ones])
y_np = np.concatenate([y_zeros, y_ones])
# Plot x_zeros and x_ones on the same graph
plt.scatter(x_zeros[:,0], x_zeros[:,1], label='class 0')
plt.scatter(x_ones[:,0], x_ones[:,1], label='class 1')
plt.legend()
plt.show()
#3) Generate a TensorFlow graph.
with tf.name_scope("placeholders"):
x = tf.constant(x_np, dtype=tf.float32)
y = tf.constant(y_np, dtype=tf.float32)
with tf.name_scope("weights"):
W = tf.Variable(tf.random.normal((2, 1)))
b = tf.Variable(tf.random.normal((1,)))
with tf.name_scope("prediction"):
y_logit = tf.squeeze(tf.matmul(x, W) + b)
# the sigmoid gives the class probability of 1
y_one_prob = tf.sigmoid(y_logit)
# Rounding P(y=1) will give the correct prediction.
y_pred = tf.round(y_one_prob)
with tf.name_scope("loss"):
# Compute the cross-entropy term for each datapoint
entropy = tf.nn.sigmoid_cross_entropy_with_logits(logits=y_logit, labels=y)
# Sum all contributions
l = tf.reduce_sum(entropy)
with tf.name_scope("optim"):
train_op = tf.compat.v1.train.AdamOptimizer(.01).minimize(l)
with tf.name_scope("summaries"):
tf.compat.v1.summary.scalar("loss", l)
merged = tf.compat.v1.summary.merge_all()
train_writer = tf.compat.v1.summary.FileWriter('logistic-train',
tf.compat.v1.get_default_graph())
#4) Train the model, get the weights, and make predictions.
#5) Plot the predicted outputs on top of the data.
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
#1) Generate the synthetic data using the following Python code snippet.
# Generate synthetic data
N = 100
# Zeros form a Gaussian centered at (-1, -1)
x_zeros = np.random.multivariate_normal(mean=np.array((-1, -1)),
cov=.1*np.eye(2), size=(N//2,))
y_zeros = np.zeros((N//2,))
# Ones form a Gaussian centered at (1, 1)
x_ones = np.random.multivariate_normal(mean=np.array((1, 1)),
cov=.1*np.eye(2), size=(N//2,))
y_ones = np.ones((N//2,))
x_np = np.vstack([x_zeros, x_ones])
y_np = np.concatenate([y_zeros, y_ones])
# Plot x_zeros and x_ones on the same graph
plt.scatter(x_zeros[:,0], x_zeros[:,1], label='class 0')
plt.scatter(x_ones[:,0], x_ones[:,1], label='class 1')
plt.legend()
plt.show()
#3) Generate a TensorFlow graph.
with tf.name_scope("placeholders"):
x = tf.constant(x_np, dtype=tf.float32)
y = tf.constant(y_np, dtype=tf.float32)
with tf.name_scope("weights"):
W = tf.Variable(tf.random.normal((2, 1)))
b = tf.Variable(tf.random.normal((1,)))
with tf.name_scope("prediction"):
y_logit = tf.squeeze(tf.matmul(x, W) + b)
# the sigmoid gives the class probability of 1
y_one_prob = tf.sigmoid(y_logit)
# Rounding P(y=1) will give the correct prediction.
y_pred = tf.round(y_one_prob)
with tf.name_scope("loss"):
# Compute the cross-entropy term for each datapoint
entropy = tf.nn.sigmoid_cross_entropy_with_logits(logits=y_logit, labels=y)
# Sum all contributions
l = tf.reduce_sum(entropy)
with tf.name_scope("optim"):
train_op = tf.compat.v1.train.AdamOptimizer(.01).minimize(l)
with tf.name_scope("summaries"):
tf.compat.v1.summary.scalar("loss", l)
merged = tf.compat.v1.summary.merge_all()
train_writer = tf.compat.v1.summary.FileWriter('logistic-train',
tf.compat.v1.get_default_graph())
#4) Train the model, get the weights, and make predictions.
#5) Plot the predicted outputs on top of the data.

More Related Content

DOCX
When running the code below I am getting some errors (see image)- The.docx
PDF
Google TensorFlow Tutorial
PDF
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
DOCX
Need help filling out the missing sections of this code- the sections.docx
PDF
maXbox starter65 machinelearning3
PPTX
Machine Learning - Introduction to Tensorflow
PPTX
Introduction to Tensorflow
PDF
The TensorFlow dance craze
When running the code below I am getting some errors (see image)- The.docx
Google TensorFlow Tutorial
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Need help filling out the missing sections of this code- the sections.docx
maXbox starter65 machinelearning3
Machine Learning - Introduction to Tensorflow
Introduction to Tensorflow
The TensorFlow dance craze

Similar to Please help fill in the missing code below in order for it run correct.docx (20)

PPTX
TensorFlow for IITians
PPTX
Font classification with 5 deep learning models using tensor flow
PPTX
TensorFlow in Practice
PPTX
Introduction to TensorFlow
PDF
GANS Project for Image idetification.pdf
PPTX
Introduction to Neural Networks and Deep Learning from Scratch
PDF
A Tour of Tensorflow's APIs
PDF
Tensor flow description of ML Lab. document
PDF
Need helping adding to the code below to plot the images from the firs.pdf
PDF
Using the code below- I need help with creating code for the following.pdf
PDF
Introducton to Convolutional Nerural Network with TensorFlow
PDF
Power ai tensorflowworkloadtutorial-20171117
PDF
TensorFlow example for AI Ukraine2016
PPTX
Explanation on Tensorflow example -Deep mnist for expert
PDF
Gentlest Introduction to Tensorflow - Part 2
PDF
Can someone please explain what the code below is doing and comment on.pdf
PDF
TensorFlow Tutorial
PDF
Neural networks using tensor flow in amazon deep learning server
PDF
What is TensorFlow and why do we use it
PDF
TensorFlow Tutorial.pdf
TensorFlow for IITians
Font classification with 5 deep learning models using tensor flow
TensorFlow in Practice
Introduction to TensorFlow
GANS Project for Image idetification.pdf
Introduction to Neural Networks and Deep Learning from Scratch
A Tour of Tensorflow's APIs
Tensor flow description of ML Lab. document
Need helping adding to the code below to plot the images from the firs.pdf
Using the code below- I need help with creating code for the following.pdf
Introducton to Convolutional Nerural Network with TensorFlow
Power ai tensorflowworkloadtutorial-20171117
TensorFlow example for AI Ukraine2016
Explanation on Tensorflow example -Deep mnist for expert
Gentlest Introduction to Tensorflow - Part 2
Can someone please explain what the code below is doing and comment on.pdf
TensorFlow Tutorial
Neural networks using tensor flow in amazon deep learning server
What is TensorFlow and why do we use it
TensorFlow Tutorial.pdf
Ad

More from madalynbb3ja (20)

DOCX
Please type out the Rational models like the example -incident---descr.docx
DOCX
Please solve this ASAP 2- Barnard's Star is one of the nearest stars t.docx
DOCX
please show step by step- asks for multile years Switzertand has long.docx
DOCX
please provide your personal reflection on what you learned doing this.docx
DOCX
please in C++ Many documents use a specific format for a person's name.docx
DOCX
Please help! Invasive species can be particularly troublesome- particu.docx
DOCX
please help me with these two thank you- What of the following describ.docx
DOCX
Please give an explaination fir those quesions! 2 3 4 5 1- Aman with r.docx
DOCX
please help me Hamid Enterprise Trial Balance for the Month of Julu 2.docx
DOCX
please help The master production schedule (MPS) is the source of all.docx
DOCX
please help raw a graph showing the change in membrane potential as a.docx
DOCX
Please create a journal entry & adjusting entries 12) Only part of th.docx
DOCX
Please Answer this 4- List three of the advantages of reflecting teles.docx
DOCX
please answer these two question- Thank you- will for sure like- Aprre.docx
DOCX
Please answer all 6 of the following ICD 10 codes for the following di.docx
DOCX
Please answer All Requlred Information -The following information app.docx
DOCX
Plants with genotype BbRryy are intercrossed- Calculate the following.docx
DOCX
pl answer (a) When can liquid metals be used as heat transfer media- -.docx
DOCX
Physiological symptoms of Jimsonweed include all EXCEPT Photophobia -&.docx
DOCX
Pester Company transferred the following assets to a newly created sub.docx
Please type out the Rational models like the example -incident---descr.docx
Please solve this ASAP 2- Barnard's Star is one of the nearest stars t.docx
please show step by step- asks for multile years Switzertand has long.docx
please provide your personal reflection on what you learned doing this.docx
please in C++ Many documents use a specific format for a person's name.docx
Please help! Invasive species can be particularly troublesome- particu.docx
please help me with these two thank you- What of the following describ.docx
Please give an explaination fir those quesions! 2 3 4 5 1- Aman with r.docx
please help me Hamid Enterprise Trial Balance for the Month of Julu 2.docx
please help The master production schedule (MPS) is the source of all.docx
please help raw a graph showing the change in membrane potential as a.docx
Please create a journal entry & adjusting entries 12) Only part of th.docx
Please Answer this 4- List three of the advantages of reflecting teles.docx
please answer these two question- Thank you- will for sure like- Aprre.docx
Please answer all 6 of the following ICD 10 codes for the following di.docx
Please answer All Requlred Information -The following information app.docx
Plants with genotype BbRryy are intercrossed- Calculate the following.docx
pl answer (a) When can liquid metals be used as heat transfer media- -.docx
Physiological symptoms of Jimsonweed include all EXCEPT Photophobia -&.docx
Pester Company transferred the following assets to a newly created sub.docx
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Pharma ospi slides which help in ospi learning
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Classroom Observation Tools for Teachers
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Cell Types and Its function , kingdom of life
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Complications of Minimal Access Surgery at WLH
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
PPH.pptx obstetrics and gynecology in nursing
STATICS OF THE RIGID BODIES Hibbelers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Pharma ospi slides which help in ospi learning
VCE English Exam - Section C Student Revision Booklet
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Classroom Observation Tools for Teachers
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Renaissance Architecture: A Journey from Faith to Humanism
Cell Types and Its function , kingdom of life
Sports Quiz easy sports quiz sports quiz
Microbial diseases, their pathogenesis and prophylaxis
Complications of Minimal Access Surgery at WLH
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

Please help fill in the missing code below in order for it run correct.docx

  • 1. Please help fill in the missing code below in order for it run correctly. Areas that are needed/missing are in highlighted in bold . import numpy as np import tensorflow as tf import matplotlib.pyplot as plt #1) Generate the synthetic data using the following Python code snippet. # Generate synthetic data N = 100 # Zeros form a Gaussian centered at (-1, -1) x_zeros = np.random.multivariate_normal(mean=np.array((-1, -1)), cov=.1*np.eye(2), size=(N//2,)) y_zeros = np.zeros((N//2,)) # Ones form a Gaussian centered at (1, 1) x_ones = np.random.multivariate_normal(mean=np.array((1, 1)), cov=.1*np.eye(2), size=(N//2,)) y_ones = np.ones((N//2,)) x_np = np.vstack([x_zeros, x_ones]) y_np = np.concatenate([y_zeros, y_ones]) # Plot x_zeros and x_ones on the same graph plt.scatter(x_zeros[:,0], x_zeros[:,1], label='class 0') plt.scatter(x_ones[:,0], x_ones[:,1], label='class 1') plt.legend() plt.show() #3) Generate a TensorFlow graph.
  • 2. with tf.name_scope("placeholders"): x = tf.constant(x_np, dtype=tf.float32) y = tf.constant(y_np, dtype=tf.float32) with tf.name_scope("weights"): W = tf.Variable(tf.random.normal((2, 1))) b = tf.Variable(tf.random.normal((1,))) with tf.name_scope("prediction"): y_logit = tf.squeeze(tf.matmul(x, W) + b) # the sigmoid gives the class probability of 1 y_one_prob = tf.sigmoid(y_logit) # Rounding P(y=1) will give the correct prediction. y_pred = tf.round(y_one_prob) with tf.name_scope("loss"): # Compute the cross-entropy term for each datapoint entropy = tf.nn.sigmoid_cross_entropy_with_logits(logits=y_logit, labels=y) # Sum all contributions l = tf.reduce_sum(entropy) with tf.name_scope("optim"): train_op = tf.compat.v1.train.AdamOptimizer(.01).minimize(l) with tf.name_scope("summaries"): tf.compat.v1.summary.scalar("loss", l) merged = tf.compat.v1.summary.merge_all() train_writer = tf.compat.v1.summary.FileWriter('logistic-train', tf.compat.v1.get_default_graph())
  • 3. #4) Train the model, get the weights, and make predictions. #5) Plot the predicted outputs on top of the data. import numpy as np import tensorflow as tf import matplotlib.pyplot as plt #1) Generate the synthetic data using the following Python code snippet. # Generate synthetic data N = 100 # Zeros form a Gaussian centered at (-1, -1) x_zeros = np.random.multivariate_normal(mean=np.array((-1, -1)), cov=.1*np.eye(2), size=(N//2,)) y_zeros = np.zeros((N//2,)) # Ones form a Gaussian centered at (1, 1) x_ones = np.random.multivariate_normal(mean=np.array((1, 1)), cov=.1*np.eye(2), size=(N//2,)) y_ones = np.ones((N//2,)) x_np = np.vstack([x_zeros, x_ones]) y_np = np.concatenate([y_zeros, y_ones]) # Plot x_zeros and x_ones on the same graph plt.scatter(x_zeros[:,0], x_zeros[:,1], label='class 0') plt.scatter(x_ones[:,0], x_ones[:,1], label='class 1') plt.legend()
  • 4. plt.show() #3) Generate a TensorFlow graph. with tf.name_scope("placeholders"): x = tf.constant(x_np, dtype=tf.float32) y = tf.constant(y_np, dtype=tf.float32) with tf.name_scope("weights"): W = tf.Variable(tf.random.normal((2, 1))) b = tf.Variable(tf.random.normal((1,))) with tf.name_scope("prediction"): y_logit = tf.squeeze(tf.matmul(x, W) + b) # the sigmoid gives the class probability of 1 y_one_prob = tf.sigmoid(y_logit) # Rounding P(y=1) will give the correct prediction. y_pred = tf.round(y_one_prob) with tf.name_scope("loss"): # Compute the cross-entropy term for each datapoint entropy = tf.nn.sigmoid_cross_entropy_with_logits(logits=y_logit, labels=y) # Sum all contributions l = tf.reduce_sum(entropy) with tf.name_scope("optim"): train_op = tf.compat.v1.train.AdamOptimizer(.01).minimize(l) with tf.name_scope("summaries"): tf.compat.v1.summary.scalar("loss", l)
  • 5. merged = tf.compat.v1.summary.merge_all() train_writer = tf.compat.v1.summary.FileWriter('logistic-train', tf.compat.v1.get_default_graph()) #4) Train the model, get the weights, and make predictions. #5) Plot the predicted outputs on top of the data.