Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Neural Network Regression Example#111

Merged
caisq merged 11 commits into
tensorflow:masterfrom
manrajgrover:nn-mlr
Aug 6, 2018
Merged

Neural Network Regression Example#111
caisq merged 11 commits into
tensorflow:masterfrom
manrajgrover:nn-mlr

Conversation

@manrajgrover

@manrajgrover manrajgrover commented Jul 11, 2018

Copy link
Copy Markdown
Contributor

This PR adds neural network regression example.


This change is Reviewable

@manrajgrover

Copy link
Copy Markdown
Contributor Author

@caisq Reworking this PR with changes discussed in #108

@manrajgrover

Copy link
Copy Markdown
Contributor Author

@caisq This can be reviewed now

@caisq

caisq commented Jul 23, 2018

Copy link
Copy Markdown
Collaborator

@manrajgrover Thanks for this PR! One high-level thought I have is: since this example shares a lot of modules and code in common with the multivariate-linear-regerssion model, we may want to merge this example with that one. We can have something like two buttons in the main HTML page, one called "train linear regressor" and another called "train NN regressor". After one of the button is clicked, the corresponding model will be trained and the loss curves plotted. That way, we not only get rid of some duplicate code, but also makes it easier for the user to compare and contrast the accuracy of the two models.

What do you think? If you agree, I can rename the multivariate-linear-regression folder to boston-housing for generality in #117

@manrajgrover

Copy link
Copy Markdown
Contributor Author

@caisq Agreed. It makes sense to combine the codebase. I can probably make the changes here itself once the other PR merges if it's okay

@caisq

caisq commented Jul 23, 2018

Copy link
Copy Markdown
Collaborator

@manrajgrover OK. I will get the comments addressed for that PR and merge it soon.

@caisq caisq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Thanks for your continuing effort to contribute examples, Manraj!

See minor comments below.

Reviewable status: 0 of 1 LGTMs obtained


boston-housing/index.js, line 30 at r3 (raw file):

export const linearRegressionModel

Important methods like this and the one below should have doc strings.


boston-housing/index.js, line 37 at r3 (raw file):

neuralNetwork

How about naming this to multiLayerPerceptronRegressionModel? I think it may be clearer because the linear regression model is, loosely speaking, also a neural network.


boston-housing/index.js, line 40 at r3 (raw file):

10

Have you done any hyperparameter tuning? Is two hidden layers of size 10 kind of an optimum? Is it possible to increase the validation accuracy by increasing the size of the neural network to a reasonable degree?

@manrajgrover

manrajgrover commented Jul 30, 2018

Copy link
Copy Markdown
Contributor Author

Have you done any hyperparameter tuning? Is two hidden layers of size 10 kind of an optimum? Is it possible to increase the validation accuracy by increasing the size of the neural network to a reasonable degree?

@caisq No, I haven't. Not sure if this is correct but it is tough to tune params using validation split after dataset shuffling since validation dataset keeps changing. I was thinking of setting aside validation data instead of using splitting after shuffle to make things easy. (I do agree tuning parameters on different splits will help prevent overfitting and generalize better but it is making tuning params tough)

Please correct me if I'm wrong

@caisq caisq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if you use validationSplit while doing Model.fit(), the validation will always be the subset at the end of the xs data and ys labels. For example, if validationSplit is 0.15, Model.fit() will always use the last 15% as the validation set. The shuffling is done after the validation split.

I suggest you do some informal hyperparameter tuning, to get a best validation error as low as reasonable. I think the current layer sizes (10) is not quite there yet. In my casual testing, I find increasing the layer sizes to about 30 - 40 helps. The reason why I'd like to see some hyperparameter tuning is so that it'll show a greater comparative advantage relative to linear regression, which we will use to justify the more complex network topology and higher computation cost in the teaching material.

Thanks.

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @manrajgrover)

@manrajgrover

Copy link
Copy Markdown
Contributor Author

Actually, if you use validationSplit while doing Model.fit(), the validation will always be the subset at the end of the xs data and ys labels. For example, if validationSplit is 0.15, Model.fit() will always use the last 15% as the validation set. The shuffling is done after the validation split.

Yes, I had read the code to understand it better. We do have shuffling happening even before validation split in data.js which I was refering to.

I suggest you do some informal hyperparameter tuning, to get a best validation error as low as reasonable. I think the current layer sizes (10) is not quite there yet. In my casual testing, I find increasing the layer sizes to about 30 - 40 helps. The reason why I'd like to see some hyperparameter tuning is so that it'll show a greater comparative advantage relative to linear regression, which we will use to justify the more complex network topology and higher computation cost in the teaching material.

@caisq Agreed.

@manrajgrover

Copy link
Copy Markdown
Contributor Author

@caisq I've tuned the params. We can also change the optimizer and activation function but for now, I've kept it as sgd and sigmoid to keep things simple and training smooth. Here is a screenshot of the output.

screen shot 2018-08-03 at 3 24 14 pm

@caisq caisq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, @manrajgrover !

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @manrajgrover)


boston-housing/index.js, line 51 at r4 (raw file):

'sigmoid'

Just curious: does sigmoid in the hidden layer give better results than relu?


boston-housing/ui.js, line 20 at r4 (raw file):

 

nit: Remove extra space. You can install clang-format and use a command like

clang-format --style=google -i ui.js

to do the formatting automatically for you.

@manrajgrover

Copy link
Copy Markdown
Contributor Author

Just curious: does sigmoid in the hidden layer give better results than relu?

@caisq Actually, training using relu with sgd was not smooth hence I changed it to sigmoid. Using adam optimizer fixed it and gave better result. I thought of keeping it simple and went with basic.

@caisq caisq merged commit fea6cfb into tensorflow:master Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants