Git Product home page Git Product logo

chrismattmann / mlwithtensorflow2ed Goto Github PK

View Code? Open in Web Editor NEW
134.0 11.0 68.0 559.59 MB

Code for Machine Learning with TensorFlow: 2nd Edition Published by Manning Publications

Home Page: http://github.com/chrismattmann/MLwithTensorFlow2ed

License: Apache License 2.0

Jupyter Notebook 99.88% Python 0.08% Dockerfile 0.01% Shell 0.03%
tensorflow tensorflow-tutorials machine-learning manning-publications ml-with-tensorflow tika python ml machine-learning-algorithms python2

mlwithtensorflow2ed's People

Contributors

chrismattmann avatar dependabot[bot] avatar philipsoutham avatar robroyce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mlwithtensorflow2ed's Issues

Listing 3.5: weights are not reinitialized, reg_lambda is ignored?

In listing 3.5, I think the weights are not reinitialized before each run. If I add a line to print out model weights, we can see that the model weights are non-zero after the first time through the loop.

sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)

for reg_lambda in np.linspace(0, 1, 100):
    w_val = sess.run(w); print(w_val) # <----------- ADDED THIS -------------
    for epoch in range(training_epochs):
        sess.run(train_op, feed_dict={X:x_train, Y:y_train})
    final_cost = sess.run(cost, feed_dict={X:x_test, Y:y_test})
    print('reg lambda', reg_lambda)
    print('final cost', final_cost)

sess.close()

This prints out:

[0. 0. 0. 0. 0. 0. 0. 0. 0.]
reg lambda 0.0
final cost 0.081058994
[ 2.5665667e-03  9.3173017e-05  1.7256942e-03 -1.4493844e-05
  1.2718090e-03 -5.8588204e-05  1.0161836e-03 -7.8277393e-05
  8.5132103e-04]
reg lambda 0.010101010101010102
final cost 0.0801239
[ 5.0976453e-03  1.8751422e-04  3.4367563e-03 -2.7644883e-05
  2.5339315e-03 -1.1590221e-04  2.0250683e-03 -1.5540000e-04
  1.6967654e-03]
reg lambda 0.020202020202020204
final cost 0.07920629
[ 7.5936671e-03  2.8300245e-04  5.1333504e-03 -3.9473085e-05
  3.7864731e-03 -1.7195975e-04  3.0267318e-03 -2.3138340e-04
  2.5363949e-03]
reg lambda 0.030303030303030304
final cost 0.0783058
[ 1.0055063e-02  3.7961689e-04  6.8156384e-03 -4.9998103e-05
  5.0295377e-03 -2.2677830e-04  4.0212511e-03 -3.0624296e-04
  3.3702708e-03]
...SNIP...

I think the correct behavior is to reinitialize the weights for each value of lambda. I also captured the cost for each lambda.

lambdas = []; costs = []                   # <-------- ADD THIS --------

for reg_lambda in np.linspace(0, 1, 100):
    sess.run(init)                         # <-------- ADD THIS --------
    for epoch in range(training_epochs):
        sess.run(train_op, feed_dict={X:x_train, Y:y_train})
    final_cost = sess.run(cost, feed_dict={X:x_test, Y:y_test})
    print('reg lambda', reg_lambda)
    print('final cost', final_cost)
    lambdas.append(reg_lambda); costs.append(final_cost) # <-------- ADD THIS --------

sess.close()

Now if plot lambdas vs cost, it's a horizontal line.

image

It seems that changing reg_lambda is having no effect, but that's not easy to see when the weights are reused.

Listing 4.6: errors should be absolute values?

The first line in the listing sums the error values, but since some errors are positive and some are negative, they have the effect of cancelling out and lowering the error measurement.

>>> avg_error = functools.reduce(lambda a,b: a+b, (trY2-Y_train))
10683.684611765864

I believe it should be:

>>> avg_error = functools.reduce(lambda a,b: a+b, np.abs(trY2-Y_train))
178465.4145040395

Or even more succinctly, reuse the error vector computed in an earlier step:

>>> avg_error = np.sum(error)
178465.41450403954

Chapter 4 listing not working in TensorFlow 2

Hello,
I have reached chapter 4 and tried to replicate its notebook, but it doesn't seem to work properly, as it's not learning the proper values. The loss output is 0 from the beginning, so there is probably an issue there in how it's calculated.

I am investigating this issue, so I will come back to you if I find a fix

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.