Skip to content

Commit 817d34a

Browse files
committed
revert to unaliased numpy
1 parent 4cf1adb commit 817d34a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

notebooks_en/2_Logistic_Regression.ipynb

+8-10
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,7 @@
693693
"The main function you will need is `autograd.grad()`, which takes a scalar-valued Python function as argument, and returns another function that evaluates to its derivative. \n",
694694
"It's what we use in the optimization loop to perform gradient descent.\n",
695695
"\n",
696-
"In addition, `autograd.numpy` is a wrapper to the NumPy library. This allows you to call your favorite NumPy methods with `autograd` keeping track of every operation so it can give you the derivative (via the chain rule).\n",
697-
"We ill import it using the alias (`as np`), consistent with the tutorials and documentation that you will find online.\n",
698-
"Up to now in the _Engineering Computations_ series of modules, we had refrained from using the aliased form of the import statements, just to have more explicit and readable code. "
696+
"In addition, `autograd.numpy` is a wrapper to the NumPy library. This allows you to call your favorite NumPy methods with `autograd` keeping track of every operation so it can give you the derivative (via the chain rule)."
699697
]
700698
},
701699
{
@@ -705,7 +703,7 @@
705703
"outputs": [],
706704
"source": [
707705
"# import the autograd-wrapped version of numpy\n",
708-
"import autograd.numpy as np"
706+
"from autograd import numpy"
709707
]
710708
},
711709
{
@@ -732,11 +730,11 @@
732730
"metadata": {},
733731
"outputs": [],
734732
"source": [
735-
"# note: the namespace np is the autograd wrapper to NumPy\n",
733+
"# note: the namespace numpy is the autograd wrapper to NumPy\n",
736734
"\n",
737735
"def logistic(z):\n",
738736
" '''The logistic function'''\n",
739-
" return 1 / (1 + np.exp(-z))\n",
737+
" return 1 / (1 + numpy.exp(-z))\n",
740738
" \n",
741739
"def logistic_model(params, x):\n",
742740
" '''A prediction model based on the logistic function composed with wx+b\n",
@@ -756,7 +754,7 @@
756754
" model: the Python function for the logistic model\n",
757755
" x, y: arrays of input data to the model'''\n",
758756
" y_pred = model(params, x)\n",
759-
" return -np.mean(y * np.log(y_pred) + (1-y) * np.log(1 - y_pred))"
757+
" return -numpy.mean(y * numpy.log(y_pred) + (1-y) * numpy.log(1 - y_pred))"
760758
]
761759
},
762760
{
@@ -816,7 +814,7 @@
816814
],
817815
"source": [
818816
"numpy.random.seed(0)\n",
819-
"params = np.random.rand(2)\n",
817+
"params = numpy.random.rand(2)\n",
820818
"print(params)"
821819
]
822820
},
@@ -891,9 +889,9 @@
891889
"source": [
892890
"max_iter = 5000\n",
893891
"i = 0\n",
894-
"descent = np.ones(len(params))\n",
892+
"descent = numpy.ones(len(params))\n",
895893
"\n",
896-
"while np.linalg.norm(descent) > 0.001 and i < max_iter:\n",
894+
"while numpy.linalg.norm(descent) > 0.001 and i < max_iter:\n",
897895
"\n",
898896
" descent = gradient(params, logistic_model, x_data, y_data)\n",
899897
" params = params - descent * 0.01\n",

0 commit comments

Comments
 (0)