feat: 2109s ps4

This commit is contained in:
Yadunand Prem 2024-02-27 20:34:10 +08:00
parent 19ec16430a
commit 2639234e64
No known key found for this signature in database
16 changed files with 1480 additions and 0 deletions

View File

@ -0,0 +1,91 @@
floor_area_sqm,bedrooms,schools,asking_price
60,2,3,480000.0
63,2,4,450000.0
65,2,1,480000.0
65,2,4,360000.0
66,2,5,350000.0
67,2,0,400000.0
67,2,1,430000.0
67,2,2,450000.0
67,2,3,410000.0
67,2,4,390000.0
67,2,5,390000.0
67,2,6,390000.0
68,2,1,460000.0
68,2,2,400000.0
68,2,3,370000.0
68,2,4,360000.0
68,2,6,370000.0
68,2,7,400000.0
68,2,8,370000.0
69,2,3,420000.0
70,2,3,510000.0
70,2,8,370000.0
73,2,5,370000.0
73,2,7,380000.0
83,2,1,590000.0
83,3,1,650000.0
83,3,2,550000.0
83,3,3,550000.0
83,3,4,580000.0
84,3,3,560000.0
86,3,2,560000.0
88,3,3,510000.0
89,3,1,610000.0
90,3,3,500000.0
90,3,4,520000.0
90,3,5,490000.0
91,3,0,550000.0
91,3,3,620000.0
92,3,1,490000.0
92,3,2,590000.0
92,3,3,490000.0
92,3,4,510000.0
92,3,5,490000.0
92,3,6,490000.0
92,3,7,510000.0
93,3,0,490000.0
93,3,1,660000.0
93,3,2,540000.0
93,3,3,550000.0
93,3,4,490000.0
93,3,5,510000.0
93,3,6,490000.0
93,3,7,490000.0
94,3,2,590000.0
94,3,3,550000.0
94,3,4,490000.0
94,3,5,540000.0
95,3,1,700000.0
95,3,2,620000.0
95,3,3,530000.0
95,3,4,540000.0
96,3,2,600000.0
96,3,7,480000.0
97,3,1,660000.0
97,3,2,600000.0
97,3,4,440000.0
98,3,5,450000.0
104,3,1,720000.0
105,3,0,630000.0
105,3,1,670000.0
105,3,2,670000.0
105,4,1,610000.0
108,3,1,780000.0
109,3,2,700000.0
110,3,3,670000.0
110,3,4,660000.0
111,3,3,640000.0
112,3,1,700000.0
112,3,2,660000.0
112,3,3,670000.0
112,3,4,650000.0
113,3,1,640000.0
113,3,2,590000.0
113,3,3,600000.0
113,3,4,590000.0
113,3,5,590000.0
115,3,1,720000.0
115,3,2,700000.0
119,4,3,690000.0
124,3,1,770000.0
1 floor_area_sqm bedrooms schools asking_price
2 60 2 3 480000.0
3 63 2 4 450000.0
4 65 2 1 480000.0
5 65 2 4 360000.0
6 66 2 5 350000.0
7 67 2 0 400000.0
8 67 2 1 430000.0
9 67 2 2 450000.0
10 67 2 3 410000.0
11 67 2 4 390000.0
12 67 2 5 390000.0
13 67 2 6 390000.0
14 68 2 1 460000.0
15 68 2 2 400000.0
16 68 2 3 370000.0
17 68 2 4 360000.0
18 68 2 6 370000.0
19 68 2 7 400000.0
20 68 2 8 370000.0
21 69 2 3 420000.0
22 70 2 3 510000.0
23 70 2 8 370000.0
24 73 2 5 370000.0
25 73 2 7 380000.0
26 83 2 1 590000.0
27 83 3 1 650000.0
28 83 3 2 550000.0
29 83 3 3 550000.0
30 83 3 4 580000.0
31 84 3 3 560000.0
32 86 3 2 560000.0
33 88 3 3 510000.0
34 89 3 1 610000.0
35 90 3 3 500000.0
36 90 3 4 520000.0
37 90 3 5 490000.0
38 91 3 0 550000.0
39 91 3 3 620000.0
40 92 3 1 490000.0
41 92 3 2 590000.0
42 92 3 3 490000.0
43 92 3 4 510000.0
44 92 3 5 490000.0
45 92 3 6 490000.0
46 92 3 7 510000.0
47 93 3 0 490000.0
48 93 3 1 660000.0
49 93 3 2 540000.0
50 93 3 3 550000.0
51 93 3 4 490000.0
52 93 3 5 510000.0
53 93 3 6 490000.0
54 93 3 7 490000.0
55 94 3 2 590000.0
56 94 3 3 550000.0
57 94 3 4 490000.0
58 94 3 5 540000.0
59 95 3 1 700000.0
60 95 3 2 620000.0
61 95 3 3 530000.0
62 95 3 4 540000.0
63 96 3 2 600000.0
64 96 3 7 480000.0
65 97 3 1 660000.0
66 97 3 2 600000.0
67 97 3 4 440000.0
68 98 3 5 450000.0
69 104 3 1 720000.0
70 105 3 0 630000.0
71 105 3 1 670000.0
72 105 3 2 670000.0
73 105 4 1 610000.0
74 108 3 1 780000.0
75 109 3 2 700000.0
76 110 3 3 670000.0
77 110 3 4 660000.0
78 111 3 3 640000.0
79 112 3 1 700000.0
80 112 3 2 660000.0
81 112 3 3 670000.0
82 112 3 4 650000.0
83 113 3 1 640000.0
84 113 3 2 590000.0
85 113 3 3 600000.0
86 113 3 4 590000.0
87 113 3 5 590000.0
88 115 3 1 720000.0
89 115 3 2 700000.0
90 119 4 3 690000.0
91 124 3 1 770000.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@ -0,0 +1,87 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "f64907f4",
"metadata": {},
"outputs": [],
"source": [
"# CODE TO GENERATE bias_scatter.png\n",
"import numpy as np\n",
"from sklearn.linear_model import LinearRegression"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf22eb4a",
"metadata": {},
"outputs": [],
"source": [
"X = np.array([1, 2, 3, 4, 5, 6]).reshape((-1, 1))\n",
"y = np.array([6, 7, 8, 8, 9, 11])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b185d8b9",
"metadata": {},
"outputs": [],
"source": [
"model_no_bias = LinearRegression(fit_intercept = False).fit(X, y)\n",
"model_with_bias = LinearRegression().fit(X, y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f5076cdc",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"X_with_zero = np.vstack([0, X]) # Added to show the lines passing through Feature=0\n",
"plt.scatter(X, y)\n",
"plt.plot(X_with_zero, model_no_bias.predict(X_with_zero), color = 'b', label=\"Without bias\")\n",
"plt.plot(X_with_zero, model_with_bias.predict(X_with_zero), color = 'r', label=\"With bias\")\n",
"plt.ylim(ymin=0)\n",
"plt.xlim(xmin=0, xmax=8)\n",
"plt.xlabel(\"Feature\")\n",
"plt.ylabel(\"Target\")\n",
"plt.legend(loc=\"center right\")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e68dd023",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

View File

@ -0,0 +1,24 @@
% CODE TO GENERATE grad_desc_algorithm.tex
\documentclass{article}
\usepackage{algorithm2e}
\usepackage{bm}
\begin{document}
\RestyleAlgo{ruled}
\DontPrintSemicolon
\begin{algorithm}[hbt!]
\caption{Gradient Descent for Linear Regression}
$w_0, w_1, \ldots, w_n \gets 0$\;
\For{$i\gets 1$ \KwTo $N$}{
$w'_0 \gets w_0 - \alpha\frac{\partial J(\boldsymbol{w})}{\partial w_0}$\;
$w'_1 \gets w_1 - \alpha\frac{\partial J(\boldsymbol{w})}{\partial w_1}$\;
$\vdots$\;
$w'_n \gets w_n - \alpha\frac{\partial J(\boldsymbol{w})}{\partial w_n}$\;
$w_0 \gets w'_0$\;
$w_1 \gets w'_1$\;
$\vdots$\;
$w_n \gets w'_n$\;
$loss \gets J(\boldsymbol{w})$\;
}
\end{algorithm}
\end{document}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

1278
cs2109s/labs/ps4/ps4.ipynb Normal file

File diff suppressed because one or more lines are too long