Statistics 654: Homework
Final:
(due Friday May 14, 2021)
This is a take-home Final Exam. You may ask questions of the Professor or search google. This is exam is to be completed independently.
Part 1: Make an R notebook with the file name lastname_firstname_Stat654_final_part1.Rmd and do the following:
Read the excellent blog post from the Data Science Heroes website, How to create a sequential model in Keras for R.
Run all of the code in this blog post in your R Notebook and explain each step presented. Clearly describe what kind of neural network is being fitted.
Change the neural network to use units = 4 for the first hidden layer and units = 2 for the second layer. Change the number of epochs = 40 in the fit(). How well does this neural network perform compared to the original neural network run?
Part 2: Make an R notebook with the file name lastname_firstname_Stat654_final_part2.Rmd and do the following:
Go to Alex Krizhevsky website and look over the The CIFAR-10 dataset. This is an interesting dataset with 10 different labeled classes of images.
Run all of the code from the RStudio Keras website Example cfar10 and explain each step presented. Clearly describe what kind of neural network is being fitted.
First change the number of epochs to a value <= 50 (current value is 200, at the top), so it does not run forever. This program will take a long time to run. Does it appear that it has run long enough?
Correction: I noticed that at the end of the code there is no call to the evaluate() function to compute the accuracy on the test data. You should add the following line of code to the end of the end of the cfar10 code: evaluate(model, x_test, y_test)
Hint: If you are getting an error running this program, try setting data_augmentation <- FALSE (current value is TRUE, at the top) so the code at the bottom of the program is not run. I think the problem might be the fit_image_data_generator() function, it may be giving an error with the newest version of the tensorflow R package. I am not certain about this being the error, but my code runs with this change. Hopefully this helps if your code is crashing.
This next topic is not part of the Final! This is just for your information if you are currious.
Part 3: Finally found a way to identify objects in a picture. The neural network to do this is called Yolo. Here is a blog post about how to use Yolo in R. Object detection in just 3 lines of R code using Tiny YOLO
R notebook: yolo_ver02.Rmd yolo_ver02.html yolo_ver02.pdf Two examples google_car.png busax.jpg
Homework 6:
Not collected. Practice for the the Project.
Using an three R Notebooks produce your solutions to the following questions. Start by making an R Notebook with file name Lastname_Firstname_Stat652_hw6.Rmd. Then knit the .Rmd file to either Lastname_Firstname_Stat652_hw6.docx. Use your own last name and first name in the filename. At the top of your first page you should include Name, Class, Section, and homework assignment.
The header of your R Notebooks should include
title: "Stat. 654 Homework 6"
author: "Your name"
Upload one file to Blackboard.
- Read: Chapter 7 and Chapter 8
Problems:
- Run the style transfer code in Chapter 8.
Homework 5:
(due Monday May 10, 2021)
Using an three R Notebooks produce your solutions to the following questions. Start by making an R Notebook with file name Lastname_Firstname_Stat652_hw5.Rmd. Then knit the .Rmd file to either Lastname_Firstname_Stat652_hw5.docx. Use your own last name and first name in the filename. At the top of your first page you should include Name, Class, Section, and homework assignment.
The header of your R Notebooks should include
title: "Stat. 654 Homework 5"
author: "Your name"
date: "May 10, 2021"
Upload one file to Blackboard.
- Read: Chapter 6
Problems:
- Run the code in Chapter 6.
Hint: For the hashFunction R package you will need to manually download and install the package. If you are running Windows you need to have Rtools installed.
Here is the reason that the hashFunction package is not available.
https://cran.r-project.org/web/packages/hashFunction/index.html
It fell off CRAN in October last year.
To install it, download the tar.gz file
https://cran.r-project.org/src/contrib/Archive/hashFunction/
This in RStudio click on Packages > Install
Change Install from: to Package Archive File (.tar.gz)
Browse to where you downloaded the file and then click Install.
Let me know if these steps work for you.
Hint: If you are running Windows, use this .zip file aclImdb.zip.
Project:
(due Wednesday May 14, 2021)
Make a stylized picture. Using a Neural Network.
The goal of the Project is to run the style transfer code from Chapter 8 on a picture of interest to you using a style of painting you like.
- Step 1: Find the picture to apply the style transfer to.
- Step 2: Find an example picture of the style of painting you want to apply.
- Step 3: Start with the R Notebook 8.3-neural-style-transfer.Rmd. Import your own picture and import the style of painting you like. Warning: This .Rmd file no longers works!!! You can use this alternative eager_styletransfer.R or try the links below.
- Step 4: Compare.
- Extra Credit: Research the algorithm used. Who created it? What is the cell phone app Prism? How is the neural network implemented in Keras?
Spotlight github: Neural-Style-Transfer download one picture and one style. try on CoLab.
CoLab Notebook: NeuralStyleTransfer.ipynb
Check out DeamScope App. You can google for it. I will not provide the link because it may have questionable content.
Midterm:
(due Monday May 3, 2021)
Instructions: This is a take-home midterm. Your work is to be completed individually. You may use your book, Google, and questions can be asked of the instructor. You are not to share code with others in the class.
Using an R Notebook produce your solutions to questions 1, 3, and 4. Turn in your modified R Notebook for the IMDB code from Section 3.4 and an updated ver02 of the code provided for question 5, submit your .Rmd and a .docx or .pdf. So you should submit three .Rmd files and the corresponding .docx or .pdf files.
- Explain what a tensor is in words. Give examples of 2D, 3D, 4D, and 5D tensors.
- In Section 3.4 of the Deep Learning with R book, the IMDB example is presented. Explain what the data being fitted is and what the input layer does in the neural network used in that section. Run the code from that example, try adding dropout layer(s) to see if the fit can be improved.
- When using the Gradient Decent Algorithm and Backpropogation, in which direction do updates move?
- Explain what a Convolutional Neural Network is in words. How does a convnet compare to the traditional feedforward neural network?
- Run the code from the book, A Computational Approach to Statistical Learning, from Chapter 8 casl Chapter 8. This example is related to the EMNIST dataset. Read the sample chapter Chapter 8. Use Meld to merge the changes from ver01 into ver02 of the R Notebook. Your assignment is to run the code in ver02 and write clear explanations above each R code chunk. Be sure to explain what a Feed-forward Neural Network is and what Convolutional layers are.
Question 5:
- R Project: Midterm.zip
- Spotlight Arxiv Paper: EMNIST: an extension of MNIST to handwritten letters
- Spotlight Software:
- Meld Compare text files
Quiz:
(due Monday April 26, 2021)
Build a Feed-Forward Neural Network, with one hiddlen layer, for the Palmer Penguins data using keras/tensorflow. Using the numeric columns in the penguins dataset, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, build a classification model for the species variable. Add a dropout layer using a rate of .5 and compare the results without dropout.
Note that the NA values need to be dropped or imputed before scaling the data to be used as input in the Neural Network model. Neural Networks do not run with missing values.
See the iris code from Week 1 as a template. Change the iris data to the penguins data. And finally refit the model using a .5 dropout rate.
-
iris Example
- iris01.nb.html
- iris01.nb.docx
- iris01.Rmd Corrected: perf$acc should just be perf[2]
-
Updated iris Example
- iris02.nb.html
- iris02.nb.docx
- iris02.Rmd Corrected: Using the tidymodels init_split()
Homework 4:
(due Monday April 19, 2021)
Using two R Notebooks produce your solutions to the following questions. Start by making an R Notebook with file name Lastname_Firstname_Stat652_hw4.Rmd. Then knit the .Rmd file to either Lastname_Firstname_Stat652_hw4.docx. Use your own last name and first name in the filename. At the top of your first page you should include Name, Class, Section, and homework assignment.
The header of your R Notebooks should include
title: "Stat. 654 Homework 4"
author: "Your name"
date: "April 19, 2021"
Upload one file to Blackboard.
- Read: Chapter 5
Problems:
- Run the code in Chapter 5.
- Covnets MNIST, 5.1-introduction-to-convnets.Rmd
- Covnets Dogs vs Cats, 5.2-using-convnets-with-small-datasets.Rmd
- Explanation of the file copying cats-and-dogs-dir-ver02.R
Homework 3:
(due Monday April 12, 2021)
Using an R Notebook produce your solutions to the following questions. Start by making an R Notebook with file name Lastname_Firstname_Stat654_hw3.Rmd. Then knit the .Rmd file to either Lastname_Firstname_Stat654_hw3.docx. Use your own last name and first name in the filename. At the top of your first page you should include Name, Class, Section, and homework assignment.
The header of your R Notebooks should include
title: "Stat. 654 Homework 3"
author: "Your name"
date: "April 12, 2021"
Upload one file to Blackboard.
- Read: Chapter 4
Problems:
- Watch the YouTube video series 3Blue1Brown Neural Networks
- Run the code in Chapter 4.
- Overfitting, overfitting-and-underfitting.Rmd
Homework 2:
(due Monday April 5, 2021)
Using three R Notebooks produce your output from running the code from the book in Chapter 3.
Knit the .Rmd files to either Lastname_Firstname_Stat652_hw2.docx or .pdf. Use your own last name and first name in the filename.
At the top of your first page you should include Name, Class, Section, and homework assignment.
The header of your R Notebooks should include
title: "Stat. 654 Homework 2"
author: "Your name"
date: "April 5, 2021"
- Read: Chapter 2 and Chapter 3
Problems:
- Run the code in Chapter 3.
- Binary classification, classifying-movie-reviews.Rmd
- Multi-class classification, classifying-newswires.Rmd
- Regression, predicting-house-prices.Rmd Fix: result$mae should be result, remove $mae.
Homework 1:
(due Monday March 22, 2021)
Using R Notebooks produce your output from running the code from the examples and from the book in Chapter 2.
Knit the .Rmd files to either Lastname_Firstname_Stat654_hw1.docx or .pdf. Use your own last name and first name in the filename.
At the top of your first page you should include Name, Class, Section, and homework assignment.
The header of your R Notebooks should include
title: "Stat. 654 Homework 1"
author: "Your name"
date: "March 22, 2021"
- Read: Chapter 1 and Chapter 2
Problems:
- Install R and RStudio, if you do not have them installed. Install the R package keras for use with a CPU. There is no need to install the tensorflow package separately, it is automatically installed when you install the keras R package.
- Run the cars Example.
- Run the concrete Example.
- Run the iris Example.
- Run the code in Chapter 2.