Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kshirsagarsiddharth/1f7a031eaa16a5da19382658a38bb03d to your computer and use it in GitHub Desktop.

Select an option

Save kshirsagarsiddharth/1f7a031eaa16a5da19382658a38bb03d to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The MSE tells how close a regression line is to a set of points. It does this by taking the distances from the points to the regression line (these distances are the errors). And squaring them the squaring is dome to remove negative values. It also gives weight to the larger differences. It is called mean squared errors because you're finding the average of the set of errors.\n",
"\n",
"Steps to calculate MSE\n",
"1. Find the regression line\n",
"2.Insert your X values in the equation and find the new Y values(Y')\n",
"3.subtract the new Y values from the old one to get the error.\n",
"4.Square the errors\n",
"5. Add up the errors\n",
"6. Find the mean\n",
"\n",
"What does mean square error tell you?\n",
"The smaller the mean square error the closer you are to finding the best fit line. \n",
"Depending on the data it may be impossible to get the smaller value for the mean squared error.\n",
"Mean squared error will be handy when we are finding the regression line by hand.\n",
"We could try several equations and the one which will give us the smallest mean squared error will be considered as the line of best fit.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"y = [11,20,19,17,10]\n",
"y_bar = [12,18,19.5,18,9]\n",
"summation = 0\n",
"n = len(y)\n",
"for i in range(o,n):\n",
" diffrence = y[i] - y_bar[i]\n",
" squared_diffrence = (diffrence)**2\n",
" summation = summation + squared_diffrence\n",
" \n",
"MSE = summation/n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"y = [11,20,19,17,10]\n",
"y_bar = [12,18,19.5,18,9]\n",
"summation = 0\n",
"n = len(y)\n",
"for i in range(0,n):\n",
" diffrence = y[i] - y_bar[i]\n",
" diffrence_squared = (diffrence)**2\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment