Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
3816beb
Enabled file downloading to run lab in Google colab
sdrangan Sep 15, 2020
556ac5f
Modified the unit 5 demo to put in a few more comments.
sdrangan Sep 15, 2020
da055a3
Added link to Section 3 video.
sdrangan Sep 15, 2020
478ef38
Simplified the delay matrix creation.
sdrangan Sep 20, 2020
0fa8f8e
Added first online video for Unit 6
sdrangan Sep 20, 2020
aaeab14
Added second video to unit 6.
sdrangan Sep 20, 2020
ad60587
Corrected link to in class exercise.
sdrangan Sep 22, 2020
56a3b22
Added a demo on transforms.
sdrangan Sep 22, 2020
1703bd2
Added python in-class exercises.
sdrangan Sep 25, 2020
d91d6f1
Modified the demo for improved plots and train-test split
sdrangan Sep 25, 2020
a70412b
Changed questions to refer to notebook.
sdrangan Sep 25, 2020
e521518
Added links to final videos.
sdrangan Sep 25, 2020
99fc381
Fixed the scaling in the lab and made the L1 regularization bonus.
sdrangan Oct 2, 2020
d32bbd0
Updated the PDF versions of the lectures
sdrangan Oct 2, 2020
fcd24cd
Added videos for the optimizer unit
sdrangan Oct 2, 2020
f8ca25d
Added second video lecture to Unit 7
sdrangan Oct 3, 2020
e180c0a
Corrected the scaling.
sdrangan Oct 3, 2020
9a9e2da
Add some comments to the demo.
sdrangan Oct 3, 2020
58e1c44
Added final video for unit 7.
sdrangan Oct 3, 2020
4ef46fa
Corrected link
sdrangan Oct 3, 2020
5e4aed2
Added Unit 7 link
sdrangan Oct 3, 2020
dc4495e
Updated with the new plotting.
sdrangan Oct 14, 2020
80a29f5
Added in-class exercises to SVM
sdrangan Oct 19, 2020
d04461b
Added unit 8 videos
sdrangan Oct 19, 2020
7fbe349
Added a demo for the kernels.
sdrangan Oct 20, 2020
3ececde
Corrected typo in the title
sdrangan Oct 20, 2020
6a7839b
Corrected the error that flipping x and y.
sdrangan Oct 21, 2020
eb98472
Added a downloader
sdrangan Oct 22, 2020
aedd3a2
Modified kernel section of the lecture to better explain the concepts
sdrangan Oct 24, 2020
e8e3050
Added first video for Unit 9 on neural networks
sdrangan Oct 25, 2020
a870070
Added link to second video
sdrangan Oct 25, 2020
f7c9b66
Corrected the accuracy in the demo
sdrangan Oct 26, 2020
d91f725
Modified installations instructions for librosa
sdrangan Oct 26, 2020
9d703e4
Added final video for unit
sdrangan Oct 27, 2020
03e7d49
Updated the lectures to match the videos.
sdrangan Oct 27, 2020
d769c8f
Added first videos for CNN unit.
sdrangan Oct 31, 2020
a1ff6fd
Added third video.
sdrangan Nov 1, 2020
1a33cd8
Added a file downloader
sdrangan Nov 1, 2020
a07da6b
Added in-class exercise 2
sdrangan Nov 1, 2020
a5e90f3
Added video on convolutional layers demo
sdrangan Nov 2, 2020
4f3aa99
Added video 5 in CNN
sdrangan Nov 2, 2020
36b7189
Modified the loading for colab.
sdrangan Nov 2, 2020
39e5777
Add sixth video
sdrangan Nov 3, 2020
d6e3183
Added videos for PCA unit
sdrangan Nov 9, 2020
1a8a5d2
Corrected constant in SVM
sdrangan Nov 9, 2020
f87c5f4
Neural network lab.
sdrangan Nov 16, 2020
948cc96
Added two videos for Unit 12.
sdrangan Nov 17, 2020
93e27c3
Updated PDF to match the PPTX
sdrangan Nov 18, 2020
06c841c
Added python coding problems
sdrangan Nov 24, 2020
d83124c
Renames files to be consistent with unit numbering
sdrangan Nov 24, 2020
fffc698
Added videos for clustering
sdrangan Nov 24, 2020
4bf4744
Added in-class exercises
sdrangan Sep 7, 2021
33bf5fb
Added the in-class versions
sdrangan Sep 7, 2021
5d648e5
Corrected the links in Lab 3.
sdrangan Sep 21, 2021
8053867
Updated intro slides
sdrangan Sep 3, 2024
66d2fdc
Added the colab links
sdrangan Sep 4, 2024
780f7f3
Created using Colab
sdrangan Oct 24, 2024
53007a1
Moved current versions to TF since we will modify the versions for py…
sdrangan Nov 1, 2024
0627429
Began conversion to pytorch
sdrangan Nov 1, 2024
653f2dd
Removed some older tensorflow code
sdrangan Nov 1, 2024
7a53d54
Completed transition to pytorch and added more comments
sdrangan Nov 5, 2024
b5a789e
Started conversion to pytorch
sdrangan Nov 5, 2024
e10f558
Updated to add the model loading and saving
sdrangan Nov 7, 2024
4d3eda9
Added comments for the GPU
sdrangan Nov 7, 2024
9121a00
Updated the exercise to include a PyTorch version.
sdrangan Nov 7, 2024
357e90b
Added PyTorch version.
sdrangan Nov 7, 2024
16bc798
Updated to correct the downloaded files.
sdrangan Nov 12, 2024
0762510
Created a new version of the EMNIST lab using the dataset from pytorch.
sdrangan Nov 16, 2024
96950fc
Merge branch 'master' of https://github.com/sdrangan/introml
sdrangan Nov 16, 2024
6a252c0
Added a demo using an LLM.
sdrangan Nov 19, 2024
38805ea
Moved the tensorflow versions so that I can update the demos with pyt…
sdrangan Nov 19, 2024
907f21d
Created a pytorch version of demo1 in the CNN unit
sdrangan Nov 19, 2024
f5262cc
Starting converting to pytorch
sdrangan Nov 19, 2024
646cb5b
Modified for pytorch and conversion to resnet
sdrangan Nov 19, 2024
bbdd1ee
Updated lab to pytorch version
sdrangan Nov 21, 2024
689d976
Updated the course admin for the new material
sdrangan Aug 26, 2025
4d86841
Updated the course admin for the TAs and lecture sequence
sdrangan Sep 9, 2025
ec29eda
Added kernel lecture and demos
sdrangan Oct 7, 2025
6f9f9b6
Updated the NLLS lab for the new URL
sdrangan Oct 9, 2025
3484a33
Added problems for K-NN and kernel methods
sdrangan Oct 9, 2025
3fd1ddc
Added a lab for fine-tuning
sdrangan Nov 9, 2025
ef187b6
Added a gitignore file
sdrangan Nov 10, 2025
0910043
Added placeholder for tokenization
sdrangan Nov 13, 2025
87b6c3e
Added a basic tokenizer demo
sdrangan Nov 13, 2025
a3fdeca
Corrected the output for the demo
sdrangan Nov 13, 2025
b5b4170
Added a simple demo on sentiment analysis
sdrangan Nov 13, 2025
928788d
Added intro text lecture
sdrangan Nov 18, 2025
60a42dc
Added a section on cosine similarity
sdrangan Nov 25, 2025
555fa73
Changed unit numbering
sdrangan Nov 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# LaTeX build artifacts
*.aux
*.log
*.out
*.toc
*.lof
*.lot
*.fls
*.fdb_latexmk
*.synctex.gz
*.bbl
*.blg

# Jupyter notebook checkpoints
.ipynb_checkpoints/

# Python cache and environment
__pycache__/
*.pyc
*.pyo
*.pyd
.mypy_cache/
.venv/
.env

# OS-specific clutter
.DS_Store
Thumbs.db

Binary file modified lectures/CourseAdmin.pdf
Binary file not shown.
Binary file modified lectures/CourseAdmin.pptx
Binary file not shown.
Binary file modified lectures/Lect01_IntroML.pdf
Binary file not shown.
Binary file modified lectures/Lect01_IntroML.pptx
Binary file not shown.
Binary file modified lectures/Lect03_MultLinRegression.pptx
Binary file not shown.
Binary file modified lectures/Lect05_Lasso.pdf
Binary file not shown.
Binary file modified lectures/Lect05_Lasso.pptx
Binary file not shown.
Binary file modified lectures/Lect06_LogisticReg.pdf
Binary file not shown.
Binary file modified lectures/Lect06_LogisticReg.pptx
Binary file not shown.
Binary file modified lectures/Lect07_Optim.pdf
Binary file not shown.
Binary file modified lectures/Lect07_Optim.pptx
Binary file not shown.
Binary file modified lectures/Lect08_SVM.pdf
Binary file not shown.
Binary file modified lectures/Lect08_SVM.pptx
Binary file not shown.
Binary file added lectures/Lect08b_Kernel.pdf
Binary file not shown.
Binary file added lectures/Lect08b_Kernel.pptx
Binary file not shown.
Binary file modified lectures/Lect09_NeuralNet.pdf
Binary file not shown.
Binary file modified lectures/Lect09_NeuralNet.pptx
Binary file not shown.
Binary file modified lectures/Lect10_ConvNet.pptx
Binary file not shown.
Binary file added lectures/Lect10_ConvNet_TF.pptx
Binary file not shown.
Binary file modified lectures/Lect11_PCA.pdf
Binary file not shown.
Binary file modified lectures/Lect11_PCA.pptx
Binary file not shown.
Binary file added lectures/Lect12_IntroText.pdf
Binary file not shown.
Binary file added lectures/Lect12_IntroText.pptx
Binary file not shown.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion online_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ YouTube video. You can also like the video and subscribe to the channel.

## Material Contents

Right now, we have only completed a few units, but more will be added.
Some videos still being created.

* [Unit 1: What is Machine Learning?](./unit01_intro/online/readme.md)
* Unit 2: Simple Linear Regression
* This material will be skipped for the graduate students
* [Unit 3: Multiple Linear Regression](./unit03_mult_lin_reg/online/readme.md)
* [Unit 4: Model Order Selection](./unit04_model_sel/online/readme.md)
* [Unit 5: LASSO Regularization](./unit05_lasso/online/readme.md)
* [Unit 6: Logistic Regression](./unit06_logistic/online/readme.md)
* [Unit 7: Non-linear Optimization](./unit07_optim/online/readme.md)
* [Unit 8: SVM](./unit08_svm/online/readme.md)
* [Unit 9: Neural Networks](./unit09_neural/online/readme.md)
* [Unit 10: Convolutional and Deep Networks](./unit10_cnn/online/readme.md)
* [Unit 11: PCA](./unit11_pca/online/readme.md)
* [Unit 12: Clustering](./unit12_cluster/online/readme.md)



Expand Down
34 changes: 24 additions & 10 deletions sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ to documents that don't match the number of the unit. We will fix these soon!
* Lecture: Introduction to Machine Learning [[pdf]](./lectures/Lect01_IntroML.pdf)
[[Powerpoint]](./lectures/Lect01_IntroML.pptx)
* [Lecture videos](./unit01_intro/online/readme.md)
* [Demo: Introduction to numpy vectors](./unit01_intro/demo_intro_vectors.ipynb)
* [Demo: Introduction to numpy vectors](./unit01_intro/demo_intro_vectors.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/sdrangan/introml/blob/master/unit01_intro/demo_intro_vectors.ipynb)
* Unit 2: Simple linear regression
* Lecture: Simple linear regression [[pdf]](./lectures/Lect02_SimpRegression.pdf)
[[Powerpoint]](./lectures/Lect02_SimpRegression.pptx)
* [Demo: Understanding automobile mpg](./unit02_simp_lin_reg/demo_auto_mpg.ipynb)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/sdrangan/introml/blob/master/unit02_simp_lin_reg/demo_auto_mpg.ipynb)
* [Lab: Boston housing data](./unit02_simp_lin_reg/lab_housing_partial.ipynb)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/sdrangan/introml/blob/master/unit02_simp_lin_reg/lab_housing_partial.ipynb)
* Problems [[pdf]](./unit02_simp_lin_reg/prob/prob_simp_lin_reg.pdf) [[Latex]](./unit02_simp_lin_reg/prob/prob_simp_lin_reg.tex)
* Unit 3: Multiple linear regression
* Lecture: Multiple linear regression [[pdf]](./lectures/Lect03_MultLinRegression.pdf)
Expand All @@ -58,7 +60,8 @@ to documents that don't match the number of the unit. We will fix these soon!
* Lecture: Model selection [[pdf]](./lectures/Lect04_ModelSelection.pdf)
[[Powerpoint]](./lectures/Lect04_ModelSelection.pptx)
* [Lecture videos](./unit04_model_sel/online/readme.md)
* [Demo: Polynomial order selection with cross-validation](./unit04_model_sel/demo_polyfit.ipynb)
* [Demo 1: Polynomial order selection with cross-validation](./unit04_model_sel/demo_polyfit.ipynb)
* [Demo 2: Feature transforms and model validation](./unit04_model_sel/demo2_transform.ipynb)
* [Lab: Neural decoding motor cortex signals](./unit04_model_sel/lab_neural_partial.ipynb)
* Problems [[pdf]](./unit04_model_sel/prob/prob_model_sel.pdf) [[Latex]](./unit03_model_sel/hw/hw03_model_sel.tex)
* Unit 5: Regularization and LASSO
Expand All @@ -72,7 +75,8 @@ to documents that don't match the number of the unit. We will fix these soon!
* [Unit 6: Logistic regression](./unit06_logistic/readme.md)
* Lecture: Linear classification and logistic regression
[[pdf]](./lectures/Lect06_LogisticReg.pdf)
[[Powerpoint]](./lectures/Lect06_LogisticReg.pptx)
[[Powerpoint]](./lectures/Lect06_LogisticReg.pptx)
* [Lecture videos](./unit06_logistic/online/readme.md)
* [Demo: Breast cancer diagnosis via logistic regression](./unit06_logistic/demo_breast_cancer.ipynb)
* [Lab: Genetic analysis of Down's syndrome in mice](./unit06_logistic/lab_gene_partial.ipynb)
* Problems [[pdf]](./unit06_logistic/prob/prob_logistic.pdf)
Expand All @@ -81,31 +85,36 @@ to documents that don't match the number of the unit. We will fix these soon!
* Lecture: Nonlinear optimization and gradient descent
[[pdf]](./lectures/Lect07_Optim.pdf)
[[Powerpoint]](./lectures/Lect07_Optim.pptx)
* [Lecture videos](./unit07_optim/online/readme.md)
* [Demo 1: Computing gradients](./unit07_optim/demo1_computing_gradients.ipynb)
* [Demo 2: Simple gradient descent optimization](./unit07_optim/demo2_grad_descent.ipynb)
* [Lab: Nonlinear least squares material modeling](./unit07_optim/lab_nlls_partial.ipynb)
* Problems [[pdf]](./unit07_optim/prob/prob_optim.pdf)
[[Latex]](./unit07_optim/prob/prob_optim.tex)
* [Unit 8: Support vector machines](./unit08_svm/readme.md)
* Lecture: SVM [[pdf]](./lectures/Lect08_SVM.pdf)
[[Powerpoint]](./lectures/Lect08_SVM.pptx)
* [Demo: MNIST digit classification](./unit08_svm/demo_mnist_svm.ipynb)
[[Powerpoint]](./lectures/Lect08_SVM.pptx)
* [Lecture videos](./unit08_svm/online/readme.md)
* [Demo 1: MNIST digit classification](./unit08_svm/demo_mnist_svm.ipynb)
* [Demo 2: Visualizing kernels](./unit08_svm/demo2_kernels.ipynb)
* [Lab: Extended MNIST with letters](./unit08_svm/lab_emnist_partial.ipynb)
* Problems [[pdf]](./unit08_svm/prob/prob_svm.pdf) [[Latex]](./unit08_svm/prob/prob_svm.tex)
* [Unit 9: Neural networks with Keras and Tensorflow](./unit09_neural/readme.md)
* Lecture: Neural networks [[pdf]](./lectures/Lect09_NeuralNet.pdf)
[[Powerpoint]](./lectures/Lect09_NeuralNet.pptx)
* [Lecture videos](./unit09_neural/online/readme.md)
* Supplementary notes with solved problems [[pdf]](./unit09_neural/prob/supplementary_neural.pdf) [[Latex]](./unit09_neural/prob/supplementary_neural.tex)
* [Demo 1: First neural network in Keras](./unit09_neural/demo1_synthetic.ipynb)
* [Demo 2: MNIST neural network classification](./unit09_neural/demo2_mnist_neural.ipynb)
* [Lab: Music instrument classification](./unit09_neural/lab_music_partial.ipynb)
* [In-class Exercise](./unit09_neural/in_class_exercise.ipynb)
* Problems: [[pdf]](./unit09_neural/prob/prob_neural.pdf) [[Latex]](./unit97_neural/prob/prob_neural.tex)
* [In-class Exercise](./unit09_neural/neural_inclass.ipynb)
* Problems: [[pdf]](./unit09_neural/prob/prob_neural.pdf) [[Latex]](./unit09_neural/prob/prob_neural.tex)
* [Unit 10: Convolutional and deep networks](./unit10_cnn/readme.md)
* Lecture: Convolutional and deep networks
[[pdf]](./lectures/Lect10_ConvNet.pdf)
[[Powerpoint]](./lectures/Lect10_ConvNet.pptx)
* [Setting up a GPU instance](./GCP/gpu_setup.md) (Recommended)
* [Lecture videos](./unit10_cnn/online/readme.md)
* [Demo 1: 2D convolutions and convolutional layers in keras](./unit10_cnn/demo1_convolutions.ipynb)
* [Demo 2: Creating an image set using the Flickr API](./unit10_cnn/demo2_flickr_images.ipynb)
* [Demo 3: Exploring the deep VGG16 network](./unit10_cnn/demo3_vgg16.ipynb)
Expand All @@ -117,13 +126,18 @@ to documents that don't match the number of the unit. We will fix these soon!
* [Unit 11: PCA](./pca/readme.md)
* Lecture: PCA [[pdf]](./lectures/Lect11_PCA.pdf), Modifed Note [[pdf]](./lectures/Lect11_PCA_modified.pdf)
[[Powerpoint]](./lectures/Lect11_PCA_modified.pptx)
* [Lecture videos](./unit11_pca/online/readme.md)
* [Demo 1: PCA eigen-faces-SVM](./unit11_pca/demo1_eigen_face.ipynb)
* [Demo 2: Low-rank matrix completion via embedding layers](./unit11_pca/demo2_low_rank.ipynb)
* [Lab: PCA with hyper-parameter optimization](./unit11_pca/lab_wine_partial.ipynb)
* Problems [[pdf]](./unit11_pca/prob/prob_PCA.pdf) [[Latex]](./unit11_pca/prob/prob_PCA.tex)
* [Unit 12: Clustering and EM](./unit12_cluster/readme.md)
* Lecture: Clustering and EM [[pdf]](./lectures/Lect12_Clustering.pdf)
[[Powerpoint]](./lectures/Lect12_Clustering.pptx)
* [Unit 12: Introduction to Text](./unit12_text)
* Lecture: Introduction to Text [[pdf](./lectures/Lect12_IntroText.pdf)] [[Powerpoint](./lectures/Lect12_IntroText.pptx)]
* [Demo 1: Tokenization](./unit12_text/demo_tokenization.ipynb)
* [Demo 2: Movie reviews](./unit12_text/demo_movie_reviews.ipynb)
* [Unit 13: Clustering and EM](./unit13_cluster/readme.md)
* Lecture: Clustering and EM [[pdf]](./lectures/Lect13_Clustering.pdf)
[[Powerpoint]](./lectures/Lect13_Clustering.pptx)
* [Demo 1: Document clustering via k-means and latent semantic analysis](./unit12_cluster/demo1_doc_cluster.ipynb)
* [Demo 2: Color quantization via k-means and EM-GMM](./unit12_cluster/demo2_kmeans_GMM_color_quantization.ipynb)
* Homework [[pdf]](./unit12_cluster/prob/prob_clustering.pdf) [[Latex]](./unit12_cluster/prob/prob_clustering.tex)
Expand Down
433 changes: 368 additions & 65 deletions unit02_simp_lin_reg/demo_auto_mpg.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion unit02_simp_lin_reg/lab_housing_partial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down
50 changes: 42 additions & 8 deletions unit03_mult_lin_reg/lab_robot_calib_partial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"\n",
"In this lab, we will illustrate the use of multiple linear regression for calibrating robot control. In addition to reviewing the concepts in the [multiple linear regression demo](./glucose.ipynb), you will see how to use multiple linear regression for time series data -- an important concept in dynamical systems such as robotics.\n",
"\n",
"The robot data for the lab is taken generously from the TU Dortmund's [Multiple Link Robot Arms Project](http://www.rst.e-technik.tu-dortmund.de/cms/en/research/robotics/TUDOR_engl/index.html). As part of the project, they have created an excellent public dataset: [MERIt](http://www.rst.e-technik.tu-dortmund.de/cms/en/research/robotics/TUDOR_engl/index.html#h3MERIt) -- A Multi-Elastic-Link Robot Identification Dataset that can be used for understanding robot dynamics. The data is from a three link robot:\n",
"The robot data for the lab is taken generously from the TU Dortmund's [TUDOR project](https://rst.etit.tu-dortmund.de/en/forschung/robotik/leichtbau/details-tudor/), TU Dortmund Omni-Elastic Robot. As part of the project, they have created an excellent public dataset: [MERIt](https://rst.etit.tu-dortmund.de/en/forschung/robotik/leichtbau/details-tudor/#c11560) -- A Multi-Elastic-Link Robot Identification Dataset that can be used for understanding robot dynamics. The data is from a three link robot:\n",
"\n",
"<img src=\"http://www.rst.e-technik.tu-dortmund.de/cms/Medienpool/redaktionelleBilder/Forschung/Schwerpunkte/TUDOR_engl/TUDORBild.png\" height=\"200\" width=\"200\">\n",
"<img src=\"https://rst.etit.tu-dortmund.de/storages/rst-etit/r/Media_Forschung/Robotik/Leichtbau/TUDORBild.png\" height=\"200\" width=\"200\">\n",
"\n",
"\n",
"We will focus on predicting the current draw into one of the joints as a function of the robot motion. Such models are essential in predicting the overall robot power consumption. Several other models could also be used."
Expand All @@ -33,19 +33,53 @@
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The full MERIt dataset can be obtained from the [MERIt site](http://www.rst.e-technik.tu-dortmund.de/cms/en/research/robotics/TUDOR_engl/index.html#h3MERIt). But, this dataset is large. Included in this repository are two of the ten experiments. Each experiments corresonds to 80 seconds of recorded motion. We will use the following files:\n",
"The full MERIt dataset can be obtained from the [MERIt site](https://rst.etit.tu-dortmund.de/en/forschung/robotik/leichtbau/details-tudor/#c11560). But, this dataset is large. Included in this repository are two of the ten experiments. Each experiments corresonds to 80 seconds of recorded motion. We will use the following files:\n",
"* [exp1.csv](./exp1.csv) for training\n",
"* [exp2.csv](./exp2.csv) for test\n",
"\n",
"Below, I have supplied the column headers in the `names` array. Use the `pd.read_csv` command to load the data. Use the `index_col` option to specify that column 0 (the one with time) is the *index* column. You can review [simple linear regression demo](..\\simp_lin_reg\\auto_mpg.ipynb) for examples of using the `pd.read_csv` command."
"If you are running this notebook on Google colab, you will need to run the following commands to load the files onto your local machine. Otherwise, if you have clone the repository, the files should be in the directory as the notebook and you can skip this step."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"File exp1.csv is already downloaded\n",
"File exp2.csv is already downloaded\n"
]
}
],
"source": [
"import os\n",
"from six.moves import urllib\n",
"\n",
"for fn_dst in ['exp1.csv', 'exp2.csv']:\n",
" fn_src = 'https://raw.githubusercontent.com/sdrangan/introml/master/unit03_mult_lin_reg/%s' % fn_dst\n",
"\n",
" if os.path.isfile(fn_dst):\n",
" print('File %s is already downloaded' % fn_dst)\n",
" else:\n",
" print('Downloaded %s' % fn_dst)\n",
" urllib.request.urlretrieve(fn_src, fn_dst)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below, I have supplied the column headers in the `names` array. Use the `pd.read_csv` command to load the training data in `exp1.csv`. Use the `index_col` option to specify that column 0 (the one with time) is the *index* column. You can review [simple linear regression demo](..\\simp_lin_reg\\auto_mpg.ipynb) for examples of using the `pd.read_csv` command."
]
},
{
Expand Down Expand Up @@ -239,7 +273,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -253,7 +287,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.8.11"
}
},
"nbformat": 4,
Expand Down
630 changes: 630 additions & 0 deletions unit04_model_sel/demo2_transform.ipynb

Large diffs are not rendered by default.

66 changes: 30 additions & 36 deletions unit04_model_sel/lab_neural_partial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
" \n",
"where `p` is the number of features and `w[j,k]` is a matrix of coefficients. In this model, `yhat[i,:]` at time `i` was only dependent on the inputs `X[i,:]` at time `i`. In signal processing, this is called a *memoryless* model. However, in many physical systems, such as those that arise in neuroscience, there is a delay between the inputs `X[i,:]` and the outputs `y[i]`. For such cases, we can use a model of the form,\n",
"\n",
" yhat[i+d,k] = \\sum_{k=0}^d \\sum_{j=0}^{p-1} \\sum_{m=0}^d X[i+m,j]*W[j,m,k] + b[k]\n",
" yhat[i+d,k] = \\sum_{j=0}^{p-1} \\sum_{m=0}^d X[i+m,j]*W[j,m,k] + b[k]\n",
" \n",
"where `W` is a 3-dim array of coefficients where:\n",
"\n",
Expand Down Expand Up @@ -303,26 +303,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We will look at model orders up to `dmax=15`. Create a delayed matrix data, `Xdly,ydly` from the reduced data, `Xred,yred` using `create_dly_data` with `dly=dmax`."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"dmax = 15\n",
"Now complete the following code to implement K-fold cross validation with `nfold=5` and values of delays `dtest = [0,1,...,dmax]`. \n",
"\n",
"# TODO\n",
"# Xdly, ydly = ..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Complete the following code to implement K-fold cross validation with `nfold=5` and values of delays `dtest = [0,1,...,dmax]`."
"The code also includes a progress bar using the `tqdm` package. This is very useful when you have a long computation.\n",
"\n",
"Note: Some students appeared to use the `mse` metric (i.e. RSS per sample) instead of `R^2`. That is fine. For the solution, I have computed both."
]
},
{
Expand All @@ -332,9 +317,10 @@
"outputs": [],
"source": [
"import sklearn.model_selection \n",
"import tqdm.notebook\n",
"\n",
"# Number of folds\n",
"nfold = 5\n",
"nfold = 5 # Number of folds\n",
"dmax = 15 # maximum number of delays\n",
"\n",
"# TODO: Create a k-fold object\n",
"# kf = sklearn.model_selection.KFold(...)\n",
Expand All @@ -345,31 +331,39 @@
"\n",
"# TODO. \n",
"# Initialize a matrix Rsq to hold values of the R^2 across the model orders and folds.\n",
"# Rsq = np.zeros(...)\n",
"# Alternatively, you can also create an RSS matrix\n",
"\n",
"# Create a progress bar. Note there are nd*nfold total fits.\n",
"pbar = tqdm.notebook.tqdm(\n",
" total=nfold*nd, initial=0,\n",
" unit='fits', unit_divisor=nd, desc='Model order test')\n",
"\n",
"# Loop over the folds\n",
"for isplit, Ind in enumerate(kf.split(Xdly)):\n",
" \n",
" print(\"fold = %d \" % isplit)\n",
" \n",
" # Get the training data in the split\n",
" Itr, Its = Ind \n",
"\n",
" for it, d in enumerate(dtest):\n",
" # TODO: \n",
" # Xdly1 = Xdly with the columns corresponding to only the `d+1` most recent times.\n",
"for it, d in enumerate(dtest):\n",
" # TODO: \n",
" # Create the delayed data using the create_dly_function from the reduced\n",
" # data Xred, yred\n",
" # Xdly, ydly = create_dly_data(...) \n",
" \n",
" # Loop over the folds\n",
" for isplit, Ind in enumerate(kf.split(Xdly)):\n",
"\n",
" # Get the training data in the split\n",
" Itr, Its = Ind \n",
"\n",
" # TODO\n",
" # Split the data (Xdly1,ydly) into training and test\n",
" # Split the data (Xdly,ydly) into training and test\n",
" # Xtr = ...\n",
" # ytr = ...\n",
" # Xts = ...\n",
" # yts = ...\n",
" \n",
" # TODO: Fit data on training data\n",
" # TODO: Fit data on training data \n",
"\n",
" # TODO: Measure the R^2 vale on test data and store in the matrix Rsq\n",
" \n",
" # TODO: Measure the R^2 vale on test data and store in the matrix Rsq "
" pbar.update(1)\n",
"pbar.close() "
]
},
{
Expand Down
Loading