diff --git a/.gitignore b/.gitignore
old mode 100755
new mode 100644
index 848d2a0d..f04b506b
--- a/.gitignore
+++ b/.gitignore
@@ -108,3 +108,4 @@ venv.bak/
*.pkl
*-solved.ipynb
+.idea/
\ No newline at end of file
diff --git a/Exercise1/exercise1.ipynb b/Exercise1/exercise1.ipynb
index fe13e3d4..6f921a48 100755
--- a/Exercise1/exercise1.ipynb
+++ b/Exercise1/exercise1.ipynb
@@ -168,7 +168,7 @@
"\n",
"Execute the next cell to grade your solution to the first part of this exercise.\n",
"\n",
- "*You should now submit you solutions.*"
+ "*You should now submit your solutions.*"
]
},
{
@@ -192,7 +192,7 @@
"\n",
"Now you will implement linear regression with one variable to predict profits for a food truck. Suppose you are the CEO of a restaurant franchise and are considering different cities for opening a new outlet. The chain already has trucks in various cities and you have data for profits and populations from the cities. You would like to use this data to help you select which city to expand to next. \n",
"\n",
- "The file `Data/ex1data1.txt` contains the dataset for our linear regression problem. The first column is the population of a city and the second column is the profit of a food truck in that city. A negative value for profit indicates a loss. \n",
+ "The file `Data/ex1data1.txt` contains the dataset for our linear regression problem. The first column is the population of a city (in 10,000s) and the second column is the profit of a food truck in that city (in $10,000s). A negative value for profit indicates a loss. \n",
"\n",
"We provide you with the code needed to load this data. The dataset is loaded from the data file into the variables `x` and `y`:"
]
@@ -371,7 +371,7 @@
"\n",
"As you perform gradient descent to learn minimize the cost function $J(\\theta)$, it is helpful to monitor the convergence by computing the cost. In this section, you will implement a function to calculate $J(\\theta)$ so you can check the convergence of your gradient descent implementation. \n",
"\n",
- "Your next task is to complete the code for the function `computeCost` which computes $J(\\theta)$. As you are doing this, remember that the variables $X$ and $y$ are not scalar values. $X$ is a matrix whose rows represent the examples from the training set and $y$ is a vector whose each elemennt represent the value at a given row of $X$.\n",
+ "Your next task is to complete the code for the function `computeCost` which computes $J(\\theta)$. As you are doing this, remember that the variables $X$ and $y$ are not scalar values. $X$ is a matrix whose rows represent the examples from the training set and $y$ is a vector whose each element represent the value at a given row of $X$.\n",
""
]
},
@@ -508,7 +508,7 @@
" X : array_like\n",
" The input dataset of shape (m x n+1).\n",
" \n",
- " y : arra_like\n",
+ " y : array_like\n",
" Value at given features. A vector of shape (m, ).\n",
" \n",
" theta : array_like\n",
@@ -845,7 +845,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "*You should not submit your solutions.*"
+ "*You should now submit your solutions.*"
]
},
{
@@ -1299,7 +1299,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.4"
+ "version": "3.6.6"
}
},
"nbformat": 4,
diff --git a/Exercise1/utils.py b/Exercise1/utils.py
index d0c909d5..b92e3cf5 100755
--- a/Exercise1/utils.py
+++ b/Exercise1/utils.py
@@ -19,7 +19,9 @@ def __init__(self):
'Computing Cost (for multiple variables)',
'Gradient Descent (for multiple variables)',
'Normal Equations']
- super().__init__('linear-regression', part_names)
+ part_names_key = ['DCRbJ', 'BGa4S', 'b65eO', 'BbS8u', 'FBlE2', 'RZAZC', '7m5Eu']
+ assignment_key = 'UkTlA-FyRRKV5ooohuwU6A'
+ super().__init__('linear-regression', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 8):
diff --git a/Exercise2/exercise2.ipynb b/Exercise2/exercise2.ipynb
index 39983d90..79911886 100755
--- a/Exercise2/exercise2.ipynb
+++ b/Exercise2/exercise2.ipynb
@@ -817,7 +817,7 @@
"print('Cost at test theta : {:.2f}'.format(cost))\n",
"print('Expected cost (approx): 3.16\\n')\n",
"\n",
- "print('Gradient at initial theta (zeros) - first five values only:')\n",
+ "print('Gradient at test theta - first five values only:')\n",
"print('\\t[{:.4f}, {:.4f}, {:.4f}, {:.4f}, {:.4f}]'.format(*grad[:5]))\n",
"print('Expected gradients (approx) - first five values only:')\n",
"print('\\t[0.3460, 0.1614, 0.1948, 0.2269, 0.0922]')"
diff --git a/Exercise2/utils.py b/Exercise2/utils.py
index 7c52dbe4..8e5e6a98 100755
--- a/Exercise2/utils.py
+++ b/Exercise2/utils.py
@@ -119,7 +119,9 @@ def __init__(self):
'Predict',
'Regularized Logistic Regression Cost',
'Regularized Logistic Regression Gradient']
- super().__init__('logistic-regression', part_names)
+ part_names_key = ['sFxIn', 'yvXBE', 'HerlY', '9fxV6', 'OddeL', 'aUo3H']
+ assignment_key = 'JvOPouj-S-ys8KjYcPYqrg'
+ super().__init__('logistic-regression', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 7):
diff --git a/Exercise3/exercise3.ipynb b/Exercise3/exercise3.ipynb
index c5771719..044d3634 100755
--- a/Exercise3/exercise3.ipynb
+++ b/Exercise3/exercise3.ipynb
@@ -373,7 +373,7 @@
"$$\n",
"\\begin{align*}\n",
"& \\frac{\\partial J(\\theta)}{\\partial \\theta_0} = \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left( x^{(i)} \\right) - y^{(i)} \\right) x_j^{(i)} & \\text{for } j = 0 \\\\\n",
- "& \\frac{\\partial J(\\theta)}{\\partial \\theta_0} = \\left( \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left( x^{(i)} \\right) - y^{(i)} \\right) x_j^{(i)} \\right) + \\frac{\\lambda}{m} \\theta_j & \\text{for } j \\ge 1\n",
+ "& \\frac{\\partial J(\\theta)}{\\partial \\theta_j} = \\left( \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left( x^{(i)} \\right) - y^{(i)} \\right) x_j^{(i)} \\right) + \\frac{\\lambda}{m} \\theta_j & \\text{for } j \\ge 1\n",
"\\end{align*}\n",
"$$\n",
"\n",
@@ -505,7 +505,7 @@
" initial_theta = np.zeros(n + 1)\n",
" \n",
" # Set options for minimize\n",
- " options = {'maxiter', 50}\n",
+ " options = {'maxiter': 50}\n",
" \n",
" # Run minimize to obtain the optimal theta. This function will \n",
" # return a class object where theta is in `res.x` and cost in `res.fun`\n",
@@ -513,7 +513,7 @@
" initial_theta, \n",
" (X, (y == c), lambda_), \n",
" jac=True, \n",
- " method='TNC')\n",
+ " method='TNC',\n",
" options=options) \n",
" \"\"\"\n",
" # Some useful variables\n",
@@ -915,7 +915,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.4"
+ "version": "3.6.6"
}
},
"nbformat": 4,
diff --git a/Exercise3/utils.py b/Exercise3/utils.py
index 633a5636..4bf99715 100755
--- a/Exercise3/utils.py
+++ b/Exercise3/utils.py
@@ -79,8 +79,9 @@ def __init__(self):
'One-vs-All Classifier Training',
'One-vs-All Classifier Prediction',
'Neural Network Prediction Function']
-
- super().__init__('multi-class-classification-and-neural-networks', part_names)
+ part_names_key = ['jzAIf', 'LjDnh', '3yxcY', 'yNspP']
+ assignment_key = '2KZRbGlpQnyzVI8Ki4uXjw'
+ super().__init__('multi-class-classification-and-neural-networks', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 5):
diff --git a/Exercise4/exercise4.ipynb b/Exercise4/exercise4.ipynb
index d8ebee0c..5e218ec5 100755
--- a/Exercise4/exercise4.ipynb
+++ b/Exercise4/exercise4.ipynb
@@ -664,6 +664,7 @@
"Note that the symbol $*$ performs element wise multiplication in `numpy`.\n",
"\n",
"1. Accumulate the gradient from this example using the following formula. Note that you should skip or remove $\\delta_0^{(2)}$. In `numpy`, removing $\\delta_0^{(2)}$ corresponds to `delta_2 = delta_2[1:]`.\n",
+ "$$ \\Delta^{(l)} = \\Delta^{(l)} + \\delta^{(l+1)} (a^{(l)})^{(T)} $$\n",
"\n",
"1. Obtain the (unregularized) gradient for the neural network cost function by dividing the accumulated gradients by $\\frac{1}{m}$:\n",
"$$ \\frac{\\partial}{\\partial \\Theta_{ij}^{(l)}} J(\\Theta) = D_{ij}^{(l)} = \\frac{1}{m} \\Delta_{ij}^{(l)}$$\n",
@@ -672,7 +673,10 @@
"**Python/Numpy tip**: You should implement the backpropagation algorithm only after you have successfully completed the feedforward and cost functions. While implementing the backpropagation alogrithm, it is often useful to use the `shape` function to print out the shapes of the variables you are working with if you run into dimension mismatch errors.\n",
"\n",
"\n",
- "[Click here to go back and update the function `nnCostFunction` with the backpropagation algorithm](#nnCostFunction)."
+ "[Click here to go back and update the function `nnCostFunction` with the backpropagation algorithm](#nnCostFunction).\n",
+ "\n",
+ "\n",
+ "**Note:** If the iterative solution provided above is proving to be difficult to implement, try implementing the vectorized approach which is easier to implement in the opinion of the moderators of this course. You can find the tutorial for the vectorized approach [here](https://www.coursera.org/learn/machine-learning/discussions/all/threads/a8Kce_WxEeS16yIACyoj1Q)."
]
},
{
@@ -710,15 +714,27 @@
"\n",
"\n",
"
\n",
- "**Practical Tip:** Gradient checking works for any function where you are computing the cost and the gradient. Concretely, you can use the same `computeNumericalGradient` function to check if your gradient implementations for the other exercises are correct too (e.g., logistic regression’s cost function).\n",
+ " Practical Tip: Gradient checking works for any function where you are computing the cost and the gradient. Concretely, you can use the same `computeNumericalGradient` function to check if your gradient implementations for the other exercises are correct too (e.g., logistic regression’s cost function).\n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'utils' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcheckNNGradients\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnnCostFunction\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m: name 'utils' is not defined"
+ ]
+ }
+ ],
"source": [
"utils.checkNNGradients(nnCostFunction)"
]
@@ -916,7 +932,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.4"
+ "version": "3.6.6"
}
},
"nbformat": 4,
diff --git a/Exercise4/utils.py b/Exercise4/utils.py
index 6b7c3bdc..6d18b86f 100755
--- a/Exercise4/utils.py
+++ b/Exercise4/utils.py
@@ -193,7 +193,9 @@ def __init__(self):
'Sigmoid Gradient',
'Neural Network Gradient (Backpropagation)',
'Regularized Gradient']
- super().__init__('neural-network-learning', part_names)
+ part_names_key = ['aAiP2', '8ajiz', 'rXsEO', 'TvZch', 'pfIYT']
+ assignment_key = 'xolSVXukR72JH37bfzo0pg'
+ super().__init__('neural-network-learning', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 6):
diff --git a/Exercise5/Figures/cross_validation.png b/Exercise5/Figures/cross_validation.png
old mode 100755
new mode 100644
diff --git a/Exercise5/Figures/learning_curve_random.png b/Exercise5/Figures/learning_curve_random.png
old mode 100755
new mode 100644
diff --git a/Exercise5/Figures/polynomial_learning_curve.png b/Exercise5/Figures/polynomial_learning_curve.png
old mode 100755
new mode 100644
diff --git a/Exercise5/Figures/polynomial_learning_curve_reg_1.png b/Exercise5/Figures/polynomial_learning_curve_reg_1.png
old mode 100755
new mode 100644
diff --git a/Exercise5/Figures/polynomial_regression.png b/Exercise5/Figures/polynomial_regression.png
old mode 100755
new mode 100644
diff --git a/Exercise5/Figures/polynomial_regression_reg_1.png b/Exercise5/Figures/polynomial_regression_reg_1.png
old mode 100755
new mode 100644
diff --git a/Exercise5/Figures/polynomial_regression_reg_100.png b/Exercise5/Figures/polynomial_regression_reg_100.png
old mode 100755
new mode 100644
diff --git a/Exercise5/exercise5.ipynb b/Exercise5/exercise5.ipynb
index 66c4500e..5da0c5f5 100755
--- a/Exercise5/exercise5.ipynb
+++ b/Exercise5/exercise5.ipynb
@@ -19,9 +19,7 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "collapsed": true
- },
+ "metadata": {},
"outputs": [],
"source": [
"# used for manipulating directory paths\n",
@@ -141,9 +139,7 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "collapsed": true
- },
+ "metadata": {},
"outputs": [],
"source": [
"def linearRegCostFunction(X, y, theta, lambda_=0.0):\n",
@@ -359,9 +355,7 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "collapsed": true
- },
+ "metadata": {},
"outputs": [],
"source": [
"def learningCurve(X, y, Xval, yval, lambda_=0):\n",
@@ -402,7 +396,7 @@
" A vector of shape m. error_train[i] contains the training error for\n",
" i examples.\n",
" error_val : array_like\n",
- " A vecotr of shape m. error_val[i] contains the validation error for\n",
+ " A vector of shape m. error_val[i] contains the validation error for\n",
" i training examples.\n",
" \n",
" Instructions\n",
@@ -528,9 +522,7 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "collapsed": true
- },
+ "metadata": {},
"outputs": [],
"source": [
"def polyFeatures(X, p):\n",
@@ -657,7 +649,7 @@
"metadata": {},
"outputs": [],
"source": [
- "lambda_ = 100\n",
+ "lambda_ = 0\n",
"theta = utils.trainLinearReg(linearRegCostFunction, X_poly, y,\n",
" lambda_=lambda_, maxiter=55)\n",
"\n",
@@ -695,9 +687,9 @@
"\n",
"### 3.2 Optional (ungraded) exercise: Adjusting the regularization parameter\n",
"\n",
- "In this section, you will get to observe how the regularization parameter affects the bias-variance of regularized polynomial regression. You should now modify the the lambda parameter and try $\\lambda = 1, 100$. For each of these values, the script should generate a polynomial fit to the data and also a learning curve.\n",
+ "In this section, you will get to observe how the regularization parameter affects the bias-variance of regularized polynomial regression. You should now modify the lambda parameter and try $\\lambda = 1, 100$. For each of these values, the script should generate a polynomial fit to the data and also a learning curve.\n",
"\n",
- "For $\\lambda = 1$, the generated plots should look like the the figure below. You should see a polynomial fit that follows the data trend well (left) and a learning curve (right) showing that both the cross validation and training error converge to a relatively low value. This shows the $\\lambda = 1$ regularized polynomial regression model does not have the high-bias or high-variance problems. In effect, it achieves a good trade-off between bias and variance.\n",
+ "For $\\lambda = 1$, the generated plots should look like the figure below. You should see a polynomial fit that follows the data trend well (left) and a learning curve (right) showing that both the cross validation and training error converge to a relatively low value. This shows the $\\lambda = 1$ regularized polynomial regression model does not have the high-bias or high-variance problems. In effect, it achieves a good trade-off between bias and variance.\n",
"\n",
"\n",
" \n",
@@ -732,9 +724,7 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "collapsed": true
- },
+ "metadata": {},
"outputs": [],
"source": [
"def validationCurve(X, y, Xval, yval):\n",
@@ -896,9 +886,7 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "collapsed": true
- },
+ "metadata": {},
"outputs": [],
"source": []
}
diff --git a/Exercise5/utils.py b/Exercise5/utils.py
index b2340ad7..da8b9be4 100755
--- a/Exercise5/utils.py
+++ b/Exercise5/utils.py
@@ -138,7 +138,9 @@ def __init__(self):
'Learning Curve',
'Polynomial Feature Mapping',
'Validation Curve']
- super().__init__('regularized-linear-regression-and-bias-variance', part_names)
+ part_names_key = ['a6bvf', 'x4FhA', 'n3zWY', 'lLaa4', 'gyJbG']
+ assignment_key = '-wEfetVmQgG3j-mtasztYg'
+ super().__init__('regularized-linear-regression-and-bias-variance', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 6):
diff --git a/Exercise6/Figures/dataset2.png b/Exercise6/Figures/dataset2.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/dataset3.png b/Exercise6/Figures/dataset3.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/email.png b/Exercise6/Figures/email.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/email_cleaned.png b/Exercise6/Figures/email_cleaned.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/svm_c1.png b/Exercise6/Figures/svm_c1.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/svm_c100.png b/Exercise6/Figures/svm_c100.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/svm_dataset2.png b/Exercise6/Figures/svm_dataset2.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/svm_dataset3_best.png b/Exercise6/Figures/svm_dataset3_best.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/vocab.png b/Exercise6/Figures/vocab.png
old mode 100755
new mode 100644
diff --git a/Exercise6/Figures/word_indices.png b/Exercise6/Figures/word_indices.png
old mode 100755
new mode 100644
diff --git a/Exercise6/exercise6.ipynb b/Exercise6/exercise6.ipynb
index cdc43975..e7e1ffac 100755
--- a/Exercise6/exercise6.ipynb
+++ b/Exercise6/exercise6.ipynb
@@ -395,7 +395,7 @@
" You can use `svmPredict` to predict the labels on the cross\n",
" validation set. For example, \n",
" \n",
- " predictions = svmPredict(model, Xval)\n",
+ " predictions = utils.svmPredict(model, Xval)\n",
"\n",
" will return the predictions on the cross validation set.\n",
" \n",
diff --git a/Exercise6/utils.py b/Exercise6/utils.py
index 6d99cec8..4ff2c2a8 100755
--- a/Exercise6/utils.py
+++ b/Exercise6/utils.py
@@ -695,7 +695,9 @@ def __init__(self):
'Parameters (C, sigma) for Dataset 3',
'Email Processing',
'Email Feature Extraction']
- super().__init__('support-vector-machines', part_names)
+ part_names_key = ['drOLk', 'JYt9Q', 'UHwLk', 'RIiFh']
+ assignment_key = 'xHfBJWXxTdKXrUG7dHTQ3g'
+ super().__init__('support-vector-machines', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 5):
diff --git a/Exercise7/exercise7.ipynb b/Exercise7/exercise7.ipynb
index 06681122..2dbde786 100755
--- a/Exercise7/exercise7.ipynb
+++ b/Exercise7/exercise7.ipynb
@@ -52,7 +52,7 @@
"# library written for this exercise providing additional functions for assignment submission, and others\n",
"import utils\n",
"\n",
- "%load_ext autoreload \n",
+ "%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"# define the submission/grader object for this exercise\n",
diff --git a/Exercise7/utils.py b/Exercise7/utils.py
index 81109173..668802b9 100755
--- a/Exercise7/utils.py
+++ b/Exercise7/utils.py
@@ -211,7 +211,9 @@ def __init__(self):
'PCA',
'Project Data (PCA)',
'Recover Data (PCA)']
- super().__init__('k-means-clustering-and-pca', part_names)
+ part_names_key = ['7yN0U', 'G1WGM', 'ixOMV', 'AFoJK', 'vf9EL']
+ assignment_key = 'rGGTuM9gQoaikOnlhLII1A'
+ super().__init__('k-means-clustering-and-pca', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 6):
diff --git a/Exercise8/exercise8.ipynb b/Exercise8/exercise8.ipynb
index 3e4aa604..d8aeda3d 100755
--- a/Exercise8/exercise8.ipynb
+++ b/Exercise8/exercise8.ipynb
@@ -298,11 +298,10 @@
" Parameters\n",
" ----------\n",
" yval : array_like\n",
- " The validation dataset of shape (m x n) where m is the number \n",
- " of examples an n is the number of dimensions(features).\n",
+ " The ground truth labels of shape (m, ).\n",
" \n",
" pval : array_like\n",
- " The ground truth labels of shape (m, ).\n",
+ " The precomputed vector of probabilities based on mu and sigma2 parameters. It's shape is also (m, ).\n",
" \n",
" Returns\n",
" -------\n",
@@ -469,7 +468,7 @@
"\n",
"# From the matrix, we can compute statistics like average rating.\n",
"print('Average rating for movie 1 (Toy Story): %f / 5' %\n",
- " np.mean(Y[0, R[0, :]]))\n",
+ " np.mean(Y[0, R[0, :] == 1]))\n",
"\n",
"# We can \"visualize\" the ratings matrix by plotting it with imshow\n",
"pyplot.figure(figsize=(8, 8))\n",
@@ -684,7 +683,7 @@
"\n",
"$$ \\frac{\\partial J}{\\partial x_k^{(i)}} = \\sum_{j:r(i,j)=1} \\left( \\left(\\theta^{(j)}\\right)^T x^{(i)} - y^{(i,j)} \\right) \\theta_k^{(j)} $$\n",
"\n",
- "$$ \\frac{\\partial J}{\\partial \\theta_k^{(j)}} = \\sum_{i:r(i,j)=1} \\left( \\left(\\theta^{(j)}\\right)^T x^{(i)}- y^{(i,j)} \\right) x_k^{(j)} $$\n",
+ "$$ \\frac{\\partial J}{\\partial \\theta_k^{(j)}} = \\sum_{i:r(i,j)=1} \\left( \\left(\\theta^{(j)}\\right)^T x^{(i)}- y^{(i,j)} \\right) x_k^{(i)} $$\n",
"\n",
"Note that the function returns the gradient for both sets of variables by unrolling them into a single vector. After you have completed the code to compute the gradients, the next cell run a gradient check\n",
"(available in `utils.checkCostFunction`) to numerically check the implementation of your gradients (this is similar to the numerical check that you used in the neural networks exercise. If your implementation is correct, you should find that the analytical and numerical gradients match up closely.\n",
@@ -810,7 +809,7 @@
"\n",
"$$ \\frac{\\partial J}{\\partial x_k^{(i)}} = \\sum_{j:r(i,j)=1} \\left( \\left(\\theta^{(j)}\\right)^T x^{(i)} - y^{(i,j)} \\right) \\theta_k^{(j)} + \\lambda x_k^{(i)} $$\n",
"\n",
- "$$ \\frac{\\partial J}{\\partial \\theta_k^{(j)}} = \\sum_{i:r(i,j)=1} \\left( \\left(\\theta^{(j)}\\right)^T x^{(i)}- y^{(i,j)} \\right) x_k^{(j)} + \\lambda \\theta_k^{(j)} $$\n",
+ "$$ \\frac{\\partial J}{\\partial \\theta_k^{(j)}} = \\sum_{i:r(i,j)=1} \\left( \\left(\\theta^{(j)}\\right)^T x^{(i)}- y^{(i,j)} \\right) x_k^{(i)} + \\lambda \\theta_k^{(j)} $$\n",
"\n",
"This means that you just need to add $\\lambda x^{(i)}$ to the `X_grad[i,:]` variable described earlier, and add $\\lambda \\theta^{(j)}$ to the `Theta_grad[j, :]` variable described earlier.\n",
"\n",
diff --git a/Exercise8/utils.py b/Exercise8/utils.py
index 938a7bb9..5edf19cf 100755
--- a/Exercise8/utils.py
+++ b/Exercise8/utils.py
@@ -235,7 +235,9 @@ def __init__(self):
'Collaborative Filtering Gradient',
'Regularized Cost',
'Regularized Gradient']
- super().__init__('anomaly-detection-and-recommender-systems', part_names)
+ part_names_key = ['WGzrg', '80Tcg', 'KDzSh', 'wZud3', 'BP3th', 'YF0u1']
+ assignment_key = 'gkyVYM98RcWlmQ9s84QNKA'
+ super().__init__('anomaly-detection-and-recommender-systems', assignment_key, part_names, part_names_key)
def __iter__(self):
for part_id in range(1, 7):
diff --git a/README.md b/README.md
index ca997de7..ecb83e30 100755
--- a/README.md
+++ b/README.md
@@ -3,9 +3,9 @@

-This repositry contains the python versions of the programming assignments for the [Machine Learning online class](https://www.coursera.org/learn/machine-learning) taught by Professor Andrew Ng. This is perhaps the most popular introductory online machine learning class. In addition to being popular, it is also one of the best Machine learning classes any interested student can take to get started with machine learning. An unfortunate aspect of this class is that the programming assignments are in MATLAB or OCTAVE, probably because this class was made before python become the go-to language in machine learning.
+This repositry contains the python versions of the programming assignments for the [Machine Learning online class](https://www.coursera.org/learn/machine-learning) taught by Professor Andrew Ng. This is perhaps the most popular introductory online machine learning class. In addition to being popular, it is also one of the best Machine learning classes any interested student can take to get started with machine learning. An unfortunate aspect of this class is that the programming assignments are in MATLAB or OCTAVE, probably because this class was made before python became the go-to language in machine learning.
-The Python machine learning ecosystem has grown exponentially in the past few years, and still gaining momentum. I suspect that many students who want to get started with their machine learning journey would like to start it with Python also. It is for those reasons I have decided to re-write all the programming assignments in Python, so students can get acquainted with its ecosystem from the start of their learning journey.
+The Python machine learning ecosystem has grown exponentially in the past few years, and is still gaining momentum. I suspect that many students who want to get started with their machine learning journey would like to start it with Python also. It is for those reasons I have decided to re-write all the programming assignments in Python, so students can get acquainted with its ecosystem from the start of their learning journey.
These assignments work seamlessly with the class and do not require any of the materials published in the MATLAB assignments. Here are some new and useful features for these sets of assignments:
@@ -13,7 +13,11 @@ These assignments work seamlessly with the class and do not require any of the m
- The original assignment instructions have been completely re-written and the parts which used to reference MATLAB/OCTAVE functionality have been changed to reference its `python` counterpart.
- The re-written instructions are now embedded within the Jupyter Notebook along with the `python` starter code. For each assignment, all work is done solely within the notebook.
- The `python` assignments can be submitted for grading. They were tested to work perfectly well with the original Coursera grader that is currently used to grade the MATLAB/OCTAVE versions of the assignments.
-- After each part of a given assignment, the Jupyter Notebook contains a cell which prompts the user for submitting the current part of the assignment for grading.
+- After each part of a given assignment, the Jupyter Notebook contains a cell which prompts the user for submitting the current part of the assignment for grading.
+
+ ## Online workspace
+
+ You can work on the assignments in an online workspace called [Deepnote](https://www.deepnote.com/). This allows you to play around with the code and access the assignments from your browser. [
](https://beta.deepnote.com/launch?template=data-science&url=https%3A%2F%2Fgithub.com%2Fdibgerge%2Fml-coursera-python-assignments)
## Downloading the Assignments
@@ -24,7 +28,7 @@ To get started, you can start by either downloading a zip file of these assignme
Each assignment is contained in a separate folder. For example, assignment 1 is contained within the folder `Exercise1`. Each folder contains two files:
- The assignment `jupyter` notebook, which has a `.ipynb` extension. All the code which you need to write will be written within this notebook.
- A python module `utils.py` which contains some helper functions needed for the assignment. Functions within the `utils` module are called from the python notebook. You do not need to modify or add any code to this file.
-
+
## Requirements
These assignments has been tested and developed using the following libraries:
@@ -57,7 +61,7 @@ If you are on a windows machine:
Once you have installed python, create a new python environment will all the requirements using the following command:
- conda create -n machine_learning python=3.6 scipy=1 numpy=1.13 matplotlib=2.1 jupyter
+ conda env create -f environment.yml
After the new environment is setup, activate it using (windows)
@@ -96,4 +100,4 @@ If you are new to python and to `jupyter` notebooks, no worries! There is a plet
- I would like to thank professor Andrew Ng and the crew of the Stanford Machine Learning class on Coursera for such an awesome class.
-- Some of the material used, especially the code for submitting assignments for grading is based on [`mstampfer`'s](https://github.com/mstampfer/Coursera-Stanford-ML-Python) python implementation of the assignments.
\ No newline at end of file
+- Some of the material used, especially the code for submitting assignments for grading is based on [`mstampfer`'s](https://github.com/mstampfer/Coursera-Stanford-ML-Python) python implementation of the assignments.
diff --git a/environment.yml b/environment.yml
new file mode 100644
index 00000000..624707a3
--- /dev/null
+++ b/environment.yml
@@ -0,0 +1,10 @@
+name: machine_learning
+channels:
+ - defaults
+dependencies:
+ - jupyter=1.0.0
+ - matplotlib=2.1.2
+ - numpy=1.13.3
+ - requests=2.26.0
+ - python=3.6.4
+ - scipy=1.0.0
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100755
index 1054bc1c..00000000
--- a/requirements.txt
+++ /dev/null
@@ -1,174 +0,0 @@
-alabaster==0.7.10
-anaconda-client==1.6.3
-anaconda-navigator==1.6.2
-anaconda-project==0.6.0
-asn1crypto==0.22.0
-astroid==1.4.9
-astropy==2.0.1
-Babel==2.4.0
-backports.shutil-get-terminal-size==1.0.0
-backports.weakref==1.0rc1
-beautifulsoup4==4.6.0
-bitarray==0.8.1
-blaze==0.10.1
-bleach==1.5.0
-bokeh==0.12.13
-boto==2.46.1
-Bottleneck==1.2.1
-cffi==1.10.0
-chardet==3.0.3
-click==6.7
-cloudpickle==0.2.2
-clyent==1.2.2
-colorama==0.3.9
-conda==4.4.8
-contextlib2==0.5.5
-coverage==4.4.1
-cryptography==1.8.1
-cycler==0.10.0
-Cython==0.25.2
-cytoolz==0.8.2
-dask==0.14.3
-datashape==0.5.4
-decorator==4.1.2
-distributed==1.16.3
-docutils==0.13.1
-entrypoints==0.2.2
-et-xmlfile==1.0.1
-fastcache==1.0.2
-Flask==0.12.2
-Flask-Cors==3.0.2
-future==0.16.0
-gevent==1.2.1
-greenlet==0.4.12
-h5py==2.7.0
-HeapDict==1.0.0
-html5lib==0.9999999
-idna==2.5
-imagesize==0.7.1
-ipdb==0.10.3
-ipdbplugin==1.4.5
-ipykernel==4.6.1
-ipython==6.2.0
-ipython-genutils==0.2.0
-ipywidgets==6.0.0
-isort==4.2.5
-itsdangerous==0.24
-jdcal==1.3
-jedi==0.11.0
-Jinja2==2.9.6
-jsonschema==2.6.0
-jupyter==1.0.0
-jupyter-client==5.0.1
-jupyter-console==5.1.0
-jupyter-contrib-core==0.3.3
-jupyter-contrib-nbextensions==0.3.3
-jupyter-core==4.3.0
-jupyter-highlight-selected-word==0.1.0
-jupyter-latex-envs==1.4.1
-jupyter-nbextensions-configurator==0.3.0
-jupyterthemes==0.17.8
-Keras==2.0.8
-lazy-object-proxy==1.2.2
-lesscpy==0.12.0
-llvmlite==0.20.0
-locket==0.2.0
-lxml==4.1.1
-Mako==1.0.7
-Markdown==2.6.9
-MarkupSafe==0.23
-matplotlib==2.1.2
-mistune==0.7.4
-mpmath==0.19
-msgpack-python==0.4.8
-multipledispatch==0.4.9
-navigator-updater==0.1.0
-nbconvert==5.3.1
-nbformat==4.4.0
-networkx==1.11
-nltk==3.2.3
-nose==1.3.7
-notebook==5.0.0
-numba==0.35.0
-numexpr==2.6.2
-numpy==1.13.1
-numpydoc==0.6.0
-odo==0.5.0
-olefile==0.44
-openpyxl==2.4.7
-packaging==16.8
-pandas==0.20.3
-pandocfilters==1.4.1
-paramiko==2.1.2
-parso==0.1.0
-partd==0.3.8
-pathlib2==2.2.1
-patsy==0.4.1
-pep8==1.7.0
-pexpect==4.2.1
-pickleshare==0.7.4
-Pillow==5.0.0
-ply==3.10
-prompt-toolkit==1.0.15
-protobuf==3.4.0
-psutil==5.2.2
-ptyprocess==0.5.2
-py==1.4.33
-pyasn1==0.2.3
-pycosat==0.6.3
-pycparser==2.17
-pycrypto==2.6.1
-pycurl==7.43.0
-pyflakes==1.5.0
-Pygments==2.2.0
-pygpu==0.6.9
-pylint==1.6.4
-pyodbc==4.0.16
-pyOpenSSL==17.0.0
-pyparsing==2.2.0
-pytest==3.0.7
-python-dateutil==2.6.1
-pytz==2017.2
-PyWavelets==0.5.2
-PyYAML==3.12
-pyzmq==16.0.2
-QtAwesome==0.4.4
-qtconsole==4.3.0
-QtPy==1.2.1
-requests==2.14.2
-rope-py3k==0.9.4.post1
-scikit-image==0.13.0
-scikit-learn==0.19.0
-scipy==0.19.1
-scons==3.0.0a20170821
-seaborn==0.7.1
-simplegeneric==0.8.1
-singledispatch==3.4.0.3
-six==1.11.0
-snowballstemmer==1.2.1
-sortedcollections==0.5.3
-sortedcontainers==1.5.7
-Sphinx==1.5.6
-spyder==3.1.4
-SQLAlchemy==1.1.9
-statsmodels==0.8.0
-sympy==1.0
-tables==3.4.2
-tblib==1.3.2
-tensorflow==1.3.0
-tensorflow-tensorboard==0.1.5
-terminado==0.6
-testpath==0.3
-Theano==0.9.0
-toolz==0.8.2
-tornado==4.5.1
-traitlets==4.3.2
-unicodecsv==0.14.1
-wcwidth==0.1.7
-Werkzeug==0.12.2
-widgetsnbextension==2.0.0
-wrapt==1.10.10
-xlrd==1.0.0
-XlsxWriter==0.9.6
-xlwt==1.2.0
-zict==0.1.2
diff --git a/submission.py b/submission.py
index 752d1c7f..2236f4f2 100755
--- a/submission.py
+++ b/submission.py
@@ -1,21 +1,21 @@
-from urllib.parse import urlencode
-from urllib.request import urlopen
-import pickle
import json
+import os
+import pickle
from collections import OrderedDict
+
import numpy as np
-import os
+import requests
class SubmissionBase:
-
- submit_url = 'https://www-origin.coursera.org/api/' \
- 'onDemandProgrammingImmediateFormSubmissions.v1'
+ submit_url = 'https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1?includes=evaluation'
save_file = 'token.pkl'
- def __init__(self, assignment_slug, part_names):
+ def __init__(self, assignment_slug, assignment_key, part_names, part_names_key):
self.assignment_slug = assignment_slug
+ self.assignment_key = assignment_key
self.part_names = part_names
+ self.part_names_key = part_names_key
self.login = None
self.token = None
self.functions = OrderedDict()
@@ -28,24 +28,25 @@ def grade(self):
# Evaluate the different parts of exercise
parts = OrderedDict()
for part_id, result in self:
- parts[str(part_id)] = {'output': sprintf('%0.5f ', result)}
- result, response = self.request(parts)
- response = json.loads(response)
+ parts[self.part_names_key[part_id - 1]] = {'output': sprintf('%0.5f ', result)}
+ response = self.request(parts)
+ response = json.loads(response.decode("utf-8"))
# if an error was returned, print it and stop
- if 'errorMessage' in response:
- print(response['errorMessage'])
+ if 'errorCode' in response:
+ print(response['message'], response['details']['learnerMessage'])
return
# Print the grading table
print('%43s | %9s | %-s' % ('Part Name', 'Score', 'Feedback'))
print('%43s | %9s | %-s' % ('---------', '-----', '--------'))
- for part in parts:
- part_feedback = response['partFeedbacks'][part]
- part_evaluation = response['partEvaluations'][part]
+ for index, part in enumerate(parts):
+ part_feedback = response['linked']['onDemandProgrammingScriptEvaluations.v1'][0]['parts'][str(part)][
+ 'feedback']
+ part_evaluation = response['linked']['onDemandProgrammingScriptEvaluations.v1'][0]['parts'][str(part)]
score = '%d / %3d' % (part_evaluation['score'], part_evaluation['maxScore'])
- print('%43s | %9s | %-s' % (self.part_names[int(part) - 1], score, part_feedback))
- evaluation = response['evaluation']
+ print('%43s | %9s | %-s' % (self.part_names[int(index)], score, part_feedback))
+ evaluation = response['linked']['onDemandProgrammingScriptEvaluations.v1'][0]
total_score = '%d / %d' % (evaluation['score'], evaluation['maxScore'])
print(' --------------------------------')
print('%43s | %9s | %-s\n' % (' ', total_score, ' '))
@@ -71,18 +72,15 @@ def login_prompt(self):
pickle.dump((self.login, self.token), f)
def request(self, parts):
- params = {
- 'assignmentSlug': self.assignment_slug,
+ payload = {
+ 'assignmentKey': self.assignment_key,
+ 'submitterEmail': self.login,
'secret': self.token,
- 'parts': parts,
- 'submitterEmail': self.login}
-
- params = urlencode({'jsonBody': json.dumps(params)}).encode("utf-8")
- f = urlopen(self.submit_url, params)
- try:
- return 0, f.read()
- finally:
- f.close()
+ 'parts': dict(eval(str(parts)))}
+ headers = {}
+
+ r = requests.post(self.submit_url, data=json.dumps(payload), headers=headers)
+ return r.content
def __iter__(self):
for part_id in self.functions: