chapter 9: Problem with visualising
- Dominant language
- Jupyter Notebook
- Stars
- 25.6k
- Forks
- 12.7k
- PR merge metrics
- No merged PRs in 30d
Description
Hi @ageron , I tried visualizing the graph of the linear regression done in chapter 9. But unlike in the book I tried to visualize the graph for gradient descent and not Mini-batch gradient descent. However, I get an error. working with windows :)
CODE:
reset_graph()
housing = fetch_california_housing()
m, n = housing.data.shape
housing_bias = np.c_[np.ones((m, 1)), housing.data]
#computing gradient descent manually
reset_graph()
scaler = StandardScaler()
scaled_data = scaler.fit_transform(housing.data)
x_scaled = np.c_[np.ones((m, 1)), scaled_data]
now = datetime.utcnow().strftime('%d-%m-%Y(%H:%M:%S)')
root_log_dir = os.path.join(os.getcwd(), 'tf_logs')
logdir = '{}\\run-{}\\'.format(root_log_dir, now)
n_epochs = 1000
learning_rate = 0.01
X = tf.constant(x_scaled, dtype=tf.float32, name='X')
Y = tf.constant(housing.target.reshape(-1, 1), dtype=tf.float32, name='Y')
theta = tf.Variable(tf.random_uniform([n + 1, 1], -1.0, 1.0, seed=42), name='Theta')
y_pred = tf.matmul(X, theta, name='Predictions')
error = y_pred - Y
mse = tf.reduce_mean(tf.square(error), name='mse')
#using autodiff
optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)
trainig_op = optimizer.minimize(mse)
saver = tf.train.Saver()
mse_summary = tf.summary.scalar('MSE', mse)
file_writer = tf.summary.FileWriter(logdir, tf.get_default_graph())
with tf.Session() as sess:
tf.global_variables_initializer().run()
for epoch in range(n_epochs):
if epoch % 100 == 0:
print('Epoch ', epoch, mse.eval())
summary_str = mse_summary.eval()
file_writer.add_summary(summary_str)
sess.run(trainig_op)
best_theta = theta.eval()
save_path = saver.save(sess, '\\tmp\\my_model.ckpt')
print(best_theta)
file_writer.close()
OUTPUT:
Traceback (most recent call last):
File "C:/Users/fritz/Tensorflow/Handson-ML-C9.py", line 42, in
file_writer = tf.summary.FileWriter(logdir, tf.get_default_graph())
File "C:\Users\fritz\Anaconda3\envs\tensorflow_cpu\lib\site-packages\tensorflow\python\summary\writer\writer.py", line 366, in __init__
filename_suffix)
File "C:\Users\fritz\Anaconda3\envs\tensorflow_cpu\lib\site-packages\tensorflow\python\summary\writer\event_file_writer.py", line 67, in __init__
gfile.MakeDirs(self._logdir)
File "C:\Users\fritz\Anaconda3\envs\tensorflow_cpu\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 379, in recursive_create_dir
pywrap_tensorflow.RecursivelyCreateDir(compat.as_bytes(dirname), status)
File "C:\Users\fritz\Anaconda3\envs\tensorflow_cpu\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 519, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Failed to create a directory: C:\Users\fritz\Tensorflow\tf_logs/run-21-12-2019(12:14:48); Invalid argument
Process finished with exit code 1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.