Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish assignment MSE #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
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
45 changes: 6 additions & 39 deletions ml-book/assignment/MSE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 38,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -75,17 +75,9 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mean Squared Error: 0.5079999999999996\n"
]
}
],
"outputs": [],
"source": [
"def mean_squared_error(y_true, y_pred):\n",
" \"\"\"\n",
Expand Down Expand Up @@ -126,34 +118,9 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[32m.\u001b[0m\u001b[31mF\u001b[0m\u001b[32m.\u001b[0m\u001b[31m [100%]\u001b[0m\n",
"============================================ FAILURES =============================================\n",
"\u001b[31m\u001b[1m___________________________ Test_MSE.test_mean_squared_error_all_zeros ____________________________\u001b[0m\n",
"\n",
"self = <__main__.Test_MSE object at 0x000002A48765A280>\n",
"\n",
" \u001b[94mdef\u001b[39;49;00m \u001b[92mtest_mean_squared_error_all_zeros\u001b[39;49;00m(\u001b[96mself\u001b[39;49;00m):\u001b[90m\u001b[39;49;00m\n",
" \u001b[90m# Test when all predicted values are 0, the mean squared error should equal the sum of squares of actual values divided by the number of actual values\u001b[39;49;00m\u001b[90m\u001b[39;49;00m\n",
" y_true = np.array([\u001b[94m1\u001b[39;49;00m, \u001b[94m2\u001b[39;49;00m, \u001b[94m3\u001b[39;49;00m, \u001b[94m4\u001b[39;49;00m, \u001b[94m5\u001b[39;49;00m])\u001b[90m\u001b[39;49;00m\n",
" y_pred = np.array([\u001b[94m0\u001b[39;49;00m, \u001b[94m0\u001b[39;49;00m, \u001b[94m0\u001b[39;49;00m, \u001b[94m0\u001b[39;49;00m, \u001b[94m0\u001b[39;49;00m])\u001b[90m\u001b[39;49;00m\n",
"> \u001b[94massert\u001b[39;49;00m mean_squared_error(y_true, y_pred) == \u001b[94m1.0\u001b[39;49;00m\u001b[90m\u001b[39;49;00m\n",
"\u001b[1m\u001b[31mE assert 11.0 == 1.0\u001b[0m\n",
"\u001b[1m\u001b[31mE + where 11.0 = mean_squared_error(array([1, 2, 3, 4, 5]), array([0, 0, 0, 0, 0]))\u001b[0m\n",
"\n",
"\u001b[1m\u001b[31mC:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_4860\\3293745680.py\u001b[0m:12: AssertionError\n",
"\u001b[36m\u001b[1m===================================== short test summary info =====================================\u001b[0m\n",
"\u001b[31mFAILED\u001b[0m t_d77093ed2c6a42589393ccea7208dcff.py::\u001b[1mTest_MSE::test_mean_squared_error_all_zeros\u001b[0m - assert 11.0 == 1.0\n",
"\u001b[31m\u001b[31m\u001b[1m1 failed\u001b[0m, \u001b[32m2 passed\u001b[0m\u001b[31m in 0.04s\u001b[0m\u001b[0m\n"
]
}
],
"outputs": [],
"source": [
"%%ipytest -qq\n",
"\n",
Expand All @@ -168,7 +135,7 @@
" # Test when all predicted values are 0, the mean squared error should equal the sum of squares of actual values divided by the number of actual values\n",
" y_true = np.array([1, 2, 3, 4, 5])\n",
" y_pred = np.array([0, 0, 0, 0, 0])\n",
" assert mean_squared_error(y_true, y_pred) == 1.0\n",
" assert mean_squared_error(y_true, y_pred) == 10.0\n",
"\n",
" def test_mean_squared_error_length_mismatch(self):\n",
" # Test for the case of mismatched lengths\n",
Expand Down
Loading