Skip to content

Commit

Permalink
Merge pull request #3 from hoanglinh171/lu
Browse files Browse the repository at this point in the history
Lu
  • Loading branch information
hoanglinh171 authored Jan 26, 2022
2 parents 7b90192 + bfc6822 commit 91efc00
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 150 deletions.
4 changes: 2 additions & 2 deletions content/lectures/lecture05/notebook/s1-exa2-challenge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -506,7 +506,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
203 changes: 162 additions & 41 deletions content/lectures/lecture05/notebook/s1-exb1-challenge.ipynb

Large diffs are not rendered by default.

93 changes: 72 additions & 21 deletions content/lectures/lecture06/notebook/s1-exc1-challenge.ipynb

Large diffs are not rendered by default.

89 changes: 61 additions & 28 deletions content/lectures/lecture06/notebook/s1-exc2-challenge.ipynb

Large diffs are not rendered by default.

86 changes: 51 additions & 35 deletions content/lectures/lecture06/notebook/s1-exc3-challenge.ipynb

Large diffs are not rendered by default.

62 changes: 39 additions & 23 deletions content/lectures/lecture06/notebook/s2-exa1-challenge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -66,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -76,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -108,35 +108,35 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>230.1</td>\n",
" <td>37.8</td>\n",
" <td>69.2</td>\n",
" <td>22.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>44.5</td>\n",
" <td>39.3</td>\n",
" <td>45.1</td>\n",
" <td>10.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>17.2</td>\n",
" <td>45.9</td>\n",
" <td>69.3</td>\n",
" <td>9.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3</td>\n",
" <td>151.5</td>\n",
" <td>41.3</td>\n",
" <td>58.5</td>\n",
" <td>18.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4</td>\n",
" <td>180.8</td>\n",
" <td>10.8</td>\n",
" <td>58.4</td>\n",
Expand All @@ -155,7 +155,7 @@
"4 180.8 10.8 58.4 12.9"
]
},
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -174,7 +174,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -187,29 +187,29 @@
"\n",
"for i in cols:\n",
" #Set each of the predictors from the previous list as x\n",
" x = df[___]\n",
" x = df[i]\n",
" \n",
" \n",
" #\"Sales\" column is the reponse variable\n",
" y = df[___]\n",
" y = df[\"Sales\"]\n",
" \n",
" \n",
" #Splitting the data into train-test sets with 80% training data and 20% testing data. \n",
" #Set random_state as 0\n",
" xtrain, xtest, ytrain, ytest = train_test_split(___)\n",
" xtrain, xtest, ytrain, ytest = train_test_split(x, y, train_size=0.8, random_state=42)\n",
"\n",
" #Create a LinearRegression object and fit the model\n",
" lreg = LinearRegression()\n",
" lreg.fit(___)\n",
" lreg.fit(xtrain, ytrain)\n",
" \n",
" #Predict the response variable for the test set\n",
" y_pred= lreg.predict(___)\n",
" y_pred= lreg.predict(xtest)\n",
" \n",
" #Compute the MSE\n",
" MSE = mean_squared_error(___)\n",
" MSE = mean_squared_error(ytest, y_pred)\n",
" \n",
" #Append the MSE to the list\n",
" mse_list.append(___)\n"
" mse_list.append(MSE)\n"
]
},
{
Expand All @@ -221,9 +221,27 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+------------------------------+--------------------+\n",
"| Predictors | MSE |\n",
"+------------------------------+--------------------+\n",
"| ['TV'] | 10.204654118800956 |\n",
"| ['Radio'] | 23.248766588129108 |\n",
"| ['Newspaper'] | 30.620733995242563 |\n",
"| ['TV', 'Radio'] | 3.137948009068354 |\n",
"| ['TV', 'Newspaper'] | 11.062557300662816 |\n",
"| ['Radio', 'Newspaper'] | 23.2046437454446 |\n",
"| ['TV', 'Radio', 'Newspaper'] | 3.174097353976104 |\n",
"+------------------------------+--------------------+\n"
]
}
],
"source": [
"t = PrettyTable(['Predictors', 'MSE'])\n",
"\n",
Expand All @@ -244,9 +262,7 @@
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Your answer here"
]
"source": []
}
],
"metadata": {
Expand All @@ -265,7 +281,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 91efc00

Please sign in to comment.