Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
94651e6
Create 2B-1.png
KeShiEcon Jan 13, 2022
0e7e0a3
images
KeShiEcon Jan 13, 2022
8d4f7d9
images
KeShiEcon Jan 20, 2022
c912393
Merge branch 'charlesincharge:main' into main
KeShiEcon Jan 20, 2022
d9da2e4
Merge branch 'charlesincharge:main' into main
KeShiEcon Jan 27, 2022
63a877c
plots
KeShiEcon Jan 27, 2022
933c5dd
Merge branch 'main' of https://github.com/keshiecon/Caltech-CS155-2022
KeShiEcon Jan 27, 2022
39c0f06
Merge branch 'charlesincharge:main' into main
KeShiEcon Feb 3, 2022
af92a4f
data
KeShiEcon Feb 3, 2022
41d85d7
something odd
KeShiEcon Feb 10, 2022
e3ad852
Merge branch 'charlesincharge:main' into main
KeShiEcon Feb 10, 2022
35521a8
Merge branch 'charlesincharge:main' into main
KeShiEcon Feb 16, 2022
56fb4c5
image
KeShiEcon Feb 16, 2022
4b13766
Merge branch 'main' of https://github.com/keshiecon/Caltech-CS155-2022
KeShiEcon Feb 16, 2022
4abd9ac
iamge
KeShiEcon Feb 16, 2022
be9d62a
Merge branch 'charlesincharge:main' into main
KeShiEcon Feb 17, 2022
ab7fb06
image
KeShiEcon Feb 17, 2022
10aa47e
Merge branch 'main' of https://github.com/keshiecon/Caltech-CS155-2022
KeShiEcon Feb 17, 2022
0fff97c
images
KeShiEcon Feb 25, 2022
5a3f282
Merge branch 'charlesincharge:main' into main
KeShiEcon Feb 25, 2022
42e8182
images
KeShiEcon Mar 1, 2022
fedf44d
Merge branch 'charlesincharge:main' into main
KeShiEcon Mar 1, 2022
2f4e129
Merge branch 'charlesincharge:main' into main
KeShiEcon Mar 2, 2022
be816a8
Merge branch 'charlesincharge:main' into main
KeShiEcon Mar 5, 2022
175fcc6
image
KeShiEcon May 23, 2022
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
Binary file added miniprojects/LCDataDictionary.xlsx
Binary file not shown.
Binary file added miniprojects/miniproject2/2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/2-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/2-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/2-4a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/2-4b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/2-4c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method1-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method1-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method1-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method1-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method1-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method2-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method2-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method2-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method2-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method2-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method3-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method3-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method3-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method3-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method3-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprojects/miniproject2/method4-2.png
Binary file added miniprojects/miniproject2/method4-3.png
Binary file added miniprojects/miniproject2/method4-4.png
Binary file added miniprojects/miniproject2/method4-5.png
Binary file added miniprojects/miniproject2/method4-6.png
Binary file added miniprojects/miniproject2/vis1.png
Binary file added miniprojects/miniproject2/vis2.png
Binary file added miniprojects/miniproject2/vis3.png
Binary file added miniprojects/miniproject2/vis4.png
Binary file added miniprojects/miniproject3/s0.png
Binary file added miniprojects/miniproject3/s2.png
Binary file added miniprojects/miniproject3/s3.png
Binary file added miniprojects/miniproject3/s4.png
Binary file added miniprojects/miniproject3/s7.png
Binary file added miniprojects/miniproject3/tran.png
42,481 changes: 42,481 additions & 0 deletions miniprojects/sample_submission.csv

Large diffs are not rendered by default.

262 changes: 262 additions & 0 deletions sets/set1/.ipynb_checkpoints/2_notebook-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "NzymtGG5swwb"
},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/charlesincharge/Caltech-CS155-2022/blob/main/sets/set1/2_notebook.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "HWXddUdnsq3j"
},
"source": [
"# Problem 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "-0_pgK2isq3n"
},
"outputs": [],
"source": [
"# Setup:\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.metrics import mean_squared_error\n",
"from sklearn.model_selection import KFold\n",
"\n",
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "yU-lIhrbsq3o"
},
"source": [
"## Example code using the polyfit and kfold functions\n",
"\n",
"#### Note: This section is not part of the homework problem, but provides some potentially-helpful example code regarding the usage of numpy.polyfit, numpy.polyval, and sklearn.model_selection.KFold.\n",
"\n",
"First, let's generate some synthetic data: a quadratic function plus some Gaussian noise."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "P_PZPzbcsq3p"
},
"outputs": [],
"source": [
"# Coefficients of the quadratic function, y(x) = ax^2 + bx + c:\n",
"a = 2\n",
"b = 5\n",
"c = 7\n",
"\n",
"N = 200 # Number of data points\n",
"x = np.linspace(-10, 10, num = N) # x ranges from -10 to 10\n",
"# y is the quadratic function of x specified by a, b, and c, plus noise\n",
"y = a*x**2 + b*x + c + 15* np.random.randn(N)\n",
"\n",
"# Plot the data:\n",
"plt.figure()\n",
"plt.plot(x, y, marker = 'o', linewidth = 0)\n",
"\n",
"plt.xlabel('x')\n",
"plt.ylabel('y')\n",
"plt.title('Synthetic data')\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ULvjrzvOsq3q"
},
"source": [
"Next, we'll use the numpy.polyfit function to fit a quadratic polynomial to this data. We can evaluate the resulting polynomial at arbitrary points."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MqfTLtuMsq3r"
},
"outputs": [],
"source": [
"# Fit a degree-2 polynomial to the data:\n",
"degree = 2\n",
"coefficients = np.polyfit(x, y, degree)\n",
"\n",
"# Print out the resulting quadratic function:\n",
"print('We fit the following quadratic function: f(x) = %f*x^2 + %f*x + %f' % \\\n",
" (coefficients[0], coefficients[1], coefficients[2]))\n",
"\n",
"# Evaluate the fitted polynomial at x = 4:\n",
"x_test = 4\n",
"f_eval = np.polyval(coefficients, x_test)\n",
"print('\\nf(%i) = %f' % (x_test, f_eval))\n",
"\n",
"# Let's visualize our fitted quadratic:\n",
"plt.figure()\n",
"\n",
"plt.plot(x, y, marker = 'o', linewidth = 0)\n",
"plt.plot(x, np.polyval(coefficients, x), color = 'red', linewidth = 3)\n",
"\n",
"plt.legend(['Data', 'Fitted quadratic'], loc = 'best')\n",
"plt.xlabel('x')\n",
"plt.ylabel('y')\n",
"plt.title('Synthetic data with Fitted Quadratic')\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "wB6S0Fydsq3s"
},
"source": [
"Finally, assume that we'd like to perform 10-fold cross validation with this dataset. Let's divide it into training and test sets, and print out the test sets. To limit the amount of text that we are printing out, we'll modify the dataset to make it smaller."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "J5e71sjssq3s"
},
"outputs": [],
"source": [
"# Coefficients of the quadratic function, y = ax^2 + bx + c:\n",
"a = 2\n",
"b = 5\n",
"c = 7\n",
"\n",
"N = 80 # Number of points--fewer this time!\n",
"x = np.linspace(-10, 10, num = N) # x ranges from -10 to 10\n",
"# y is the quadratic function of x specified by a, b, and c, plus noise\n",
"y = a*x**2 + b*x + c + 15* np.random.randn(N)\n",
"\n",
"# Initialize kfold cross-validation object with 10 folds:\n",
"num_folds = 10\n",
"kf = KFold(n_splits=num_folds)\n",
"\n",
"# Iterate through cross-validation folds:\n",
"i = 1\n",
"for train_index, test_index in kf.split(x):\n",
" \n",
" # Print out test indices:\n",
" print('Fold ', i, ' of ', num_folds, ' test indices:', test_index)\n",
" \n",
" # Training and testing data points for this fold:\n",
" x_train, x_test = x[train_index], x[test_index]\n",
" y_train, y_test = y[train_index], y[test_index]\n",
" \n",
" i += 1"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Z5o-siOhsq3t"
},
"source": [
"## Loading the Data for Problem 2\n",
"\n",
"This code loads the data from bv_data.csv using the load_data helper function. Note that data[:, 0] is an array of all the x values in the data and data[:, 1] is an array of the corresponding y values."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "BNZDexsCsq3u"
},
"outputs": [],
"source": [
"def load_data(filename):\n",
" \"\"\"\n",
" Function loads data stored in the file filename and returns it as a numpy ndarray.\n",
" Input:\n",
" filename: given as a string.\n",
" Output:\n",
" Data contained in the file, returned as a numpy ndarray\n",
" \"\"\"\n",
" return np.loadtxt(filename, skiprows=1, delimiter=',')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "-34QBZ8Lsq3u"
},
"outputs": [],
"source": [
"data = load_data('https://raw.githubusercontent.com/charlesincharge/Caltech-CS155-2022/main/sets/set1/data/bv_data.csv')\n",
"x = data[:, 0]\n",
"y = data[:, 1]"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qhI2aAjXsq3v"
},
"source": [
"Write your code below for solving problem 2 part B:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "brdXBe--sq3v"
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"colab": {
"name": "2_notebook.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Binary file added sets/set1/2B-1.png
Binary file added sets/set1/2B-12.png
Binary file added sets/set1/2B-2.png
Binary file added sets/set1/2B-6.png
Loading