Skip to content

Instantly share code, notes, and snippets.

@infinite-Joy9l
Last active January 19, 2018 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinite-Joy9l/ee87095644f9cc6bcc640ede36aae699 to your computer and use it in GitHub Desktop.
Save infinite-Joy9l/ee87095644f9cc6bcc640ede36aae699 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For each member of the dataset, the result (Y) determines which variation of the cost function is used. The Y = 0 cost function punishes high probability estimations, and Y = 1 punishes low scores. The \"punishment\" makes the change in the gradient of ThetaCurrent - Average(CostFunction(Dataset)) greater"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def Cost_Function(X,Y,theta,m):\n",
" sumOfErrors = 0\n",
" for i in range(m):\n",
" xi = X[i]\n",
" hi = Hypothesis(theta,xi)\n",
" if Y[i] == 1:\n",
" error = Y[i] * math.log(hi)\n",
" elif Y[i] == 0:\n",
" error = (1-Y[i]) * math.log(1-hi)\n",
" sumOfErrors += error\n",
" const = -1/m\n",
" J = const * sumOfErrors\n",
" print('cost is ', J)\n",
" return J"
]
}
],
"metadata": {
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment