The assignment is written by Professor Xiaolong Wang and linear regression, logistic regression and CNN are completed by Laiwei Wei.
Assignment 1 includes 5 parts (each part is worth 20%):
- KNN
- Linear Regression
- Logistic Regression
- Neural Network in NumPy
- Classification using Neural Network
File structure:
assignment1
├── README.md (this file)
├── ece285 (source code folder)
├── *.ipynb (notebooks)
├── get_datasets.py (download script)
└── datasets (datasets folder)
Before you start, you need to run the following command (in terminal or in notebook beginning with ! ) to download the datasets:
# This command will download required datasets and put it in "./datasets".
python get_datasets.pyYou should run all code blocks in the following jupyter notebooks and write your answers to all inline questions included in the notebooks:
knn.ipynblinear_regression.ipynblogistic_regression.ipynbneural_network.ipynbclassification_nn.ipynb
Go through the notebooks to understand the structure. These notebooks will require you to complete the following implementations:
ece285/algorithms/knn.py: Implement KNN algorithmece285/algorithms/linear_regression.py: Implement linear regression algorithmece285/algorithms/logistic_regression.py: Implement logistic regression algorithmece285/layers/linear.py: Implement linear layers with arbitrary input and output dimensionsece285/layers/relu.py: Implement ReLU activation function, forward and backward passece285/layers/softmax.py: Implement softmax function to calculate class probabilitiesece285/layers/loss_func.py: Implement CrossEntropy loss, forward and backward pass
You are required to go through all the modules (the ones that are already implemented for you as well) one by one to to understand the structure. This will help you when transitioning to deep learning libraries such as PyTorch. Here are some files that you should go through that are already implemented for you:
ece285/layers/sequential.pyece285/utils/trainer.pyece285/utils/optimizer.py
After you complete all the functions and questions, you should upload the following files to Gradescope:
- 7
.pyfiles that you have to implement (knn, linear_regression, logistic_regression, linear, relu, softmax, loss_func). - 5 notebook source
.ipynbfiles - Exported PDF of notebooks(You could export jupyter notebook as PDF in web portal, do not need to install LaTeX packages) and merge them
You should organize files like this:
- Put all source files(7 python files and 5 notebooks) into a single
.zipfile then upload it on Gradescope - Merge exported PDF of notebooks into a single PDF file and upload it on Gradescope
- Edit only the parts that are asked of you. Do not change the random seed where it is set. This might not make it possible to get similar results.
- Try to avoid
forloops in all the implementations, the assignment can be solved without any for loops (vectorized implementation)
Part of our skeleton code is provided using Jupyter notebook(*.ipynb). So there we provide a short instruction about how to use Jupyter Notebook.
Jupyter notebook is a powerfull interactive developement tool. Here we could Jupyter notebook file as notebook for short.
Jupyter notebook is pre-installed on Datahub, you can just use it via web-portal. You could also install it on your local machine. Here is the official install instruction(https://jupyter.org/install), which also included how to run it via terminal.
You may find on Jupyter website, they provide Jupyter Lab. Jupyter Lab is basically a new version of Jupyter notebook with more features and different interface. The basic usage is almost the same.
All notebooks are made up with multiple blocks. There are different kinds of blocks, the most common blocks are:
- Code block
- Markdown block
For code block, you can write python code in code block, after finishing your code you could press run bottom on the jupyter note interface(normally on the top of the web interface). You can also use Ctrl + Enter or Shift + Enter to execute the block.
After you execute a block, Jupyter Notebook will execute your code with python and store all the function and variable you defined in memory. So you could still use those variables and function is other blocks.
For code blocks, you can think of jupyter notebook as a python console with an interface.
Markdown block is where you can write some text.
When you execute Markdown block(the same method as Code block), your text will be compiled using Markdown grammar, instead of executing it with python.
In our assignment, we put some inline questions in notebooks, you are supposed to answer them with text.
In all, notebooks are basically some combination of code and text.
If you run the assignment on Datahub, you do not need to set up python environment. Our code is tested on Datahub.
If you run the assignment on your local machine or other environment and meet some problems, you may need to set up python environment.
We prepare a requirements.txt file (same versions as the datahub packages) for you to install python packages. You can install the packages by running the following command in terminal:
pip install -r requirements.txtThis should solve most package issues. But if you still have some problems, we recommend you to use conda environment. You can install anaconda or miniconda by following the instruction on https://docs.anaconda.com/anaconda/install/index.html. After you install it, you can run the following command to set up python environment:
conda create -n ece285 python=3.9.5 # same python version as the datahub
conda activate ece285
pip install -r requirements.txtIf you have any questions, feel free to contact TAs.
How to unzip a zip file:
unzip XX.zip # in terminal or in notebook beginning with `!`