@@ -663,35 +663,47 @@
},
{
"cell_type": "code",
"execution_count": 479,
"execution_count": 496,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2, 3, 4])"
]
},
"execution_count": 479,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"a1 = np.array([1,2,3])\n",
"a2 = np.array([2,3,4])\n",
"a1+1"
"#So if MSE doesnt improve stop??\n",
"#TF recommends running without threshold, plotting change in MSEs, and then deciding a good threshold from that\n",
" \n",
"def der_loss(y_function, weights, )\n",
"\n",
" \n",
" \n",
"threshold = 0.0000001 #difference in MSE \n",
"learn = 0.01 #learning rate\n",
"delta = 0.1\n",
"max_iters = 1000\n",
"\n",
"def gradient_descent(y_function, weight_guess, max_iters, learn)\n",
" weight_list = [weight_guess]\n",
" iters = 0 \n",
" w_n_prev = weight_guess\n",
" \n",
" while iters < max_iter:\n",
" gradient_eval = der_loss(y_function, w_n_prev) #evaluate gradient\n",
" w_n = w_prev + learn*gradient_eval #get new weights and bias\n",
" y_eval = y_function(*w_n)\n",
"\n",
" weight_list.append(w_n)\n",
"\n",
" w_n_prev = w_n\n",
" \n",
" iters+=1 #before or after threshold check?????\n",
"\n",
" if abs(y_eval - y_function(*weight_list[step-1])) < threshold: break\n"
]
},
{
"cell_type": "code",
"execution_count": 496,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#So if MSE doesnt improve stop??\n",
"#TF recommends running without threshold, plotting change in MSEs, and then deciding a good threshold from that\n",
"\n",
"#not necessarily right, should not have delta or something\n",
"def get_new_weights(old_weights, learning, delta, y_function, y_true):\n",
" y_old_pred = y_function(*old_weights)\n",
@@ -703,17 +715,7 @@
" \n",
" change = learning*((mse_delta - mse_old)/delta)\n",
" \n",
" return old_weights - change #new weights \n",
" \n",
"\n",
"threshold = 0.0000001 #difference in MSE \n",
"learn = 0.01 #learning rate\n",
"delta = 0.1\n",
"iters = 0 \n",
"max_iters = 1000\n",
" \n",
"while iters < max_iter:\n",
" iters+=1"
" return old_weights - change #new weights "
]
},
{
@@ -1255,13 +1257,6 @@
" return df_train, df_test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Discuss why we normalize..."
]
},
{
"cell_type": "code",
"execution_count": 461,