|
42 | 42 | "n_feature = 2 # the number of features\n",
|
43 | 43 | "n_components = 2 # the number of clusters\n",
|
44 | 44 | "\n",
|
45 |
| - "n=1000 # the number of total samples" |
| 45 | + "n = 1000 # the number of total samples" |
46 | 46 | ]
|
47 | 47 | },
|
48 | 48 | {
|
|
207 | 207 | " I/P\n",
|
208 | 208 | " ----------\n",
|
209 | 209 | " X : 2D array where each row represent the training example and each column represent the feature ndarray. \n",
|
210 |
| - " Dimension(m x n)\n", |
211 |
| - " m= number of training examples\n", |
212 |
| - " n= number of features (including X_0 column of ones)\n", |
213 |
| - " y : 1D array of labels/target value for each traing example. dimension(1 x m)\n", |
| 210 | + " Dimension (n x d)\n", |
| 211 | + " n = number of training examples\n", |
| 212 | + " d = number of features (including X_0 column of ones)\n", |
| 213 | + " y : 1D array of labels/target value for each traing example. dimension(1 x n)\n", |
214 | 214 | "\n",
|
215 |
| - " weights : 1D array of fitting parameters or weights. Dimension (1 x n)\n", |
| 215 | + " weights : 1D array of fitting parameters or weights. Dimension (1 x d)\n", |
216 | 216 | "\n",
|
217 | 217 | " O/P\n",
|
218 | 218 | " -------\n",
|
219 | 219 | " cost : The cost of using theta as the parameter for linear regression to fit the data points in X and y.\n",
|
220 | 220 | " \"\"\"\n",
|
221 |
| - " m, n = X.shape\n", |
| 221 | + " n, d = X.shape\n", |
222 | 222 | " x_dot_weights = X.dot(weights)\n",
|
223 | 223 | "\n",
|
224 |
| - " cost = 1.0 / m * (-y.T.dot(np.log(sigmoid(x_dot_weights))) - (1 - y).T.dot(np.log(1 - sigmoid(x_dot_weights))))\n", |
| 224 | + " cost = 1.0 / n * (-y.T.dot(np.log(sigmoid(x_dot_weights))) - (1 - y).T.dot(np.log(1 - sigmoid(x_dot_weights))))\n", |
225 | 225 | "\n",
|
226 | 226 | " return cost"
|
227 | 227 | ]
|
|
250 | 250 | " -------\n",
|
251 | 251 | " grad: (numpy array)The gradient of the cost with respect to the parameters theta\n",
|
252 | 252 | " \"\"\"\n",
|
253 |
| - " m, n = X.shape\n", |
| 253 | + " n, d = X.shape\n", |
254 | 254 | " x_dot_weights = X.dot(weights)\n",
|
255 | 255 | "\n",
|
256 |
| - " grad = (1.0 / m )* (sigmoid(x_dot_weights) - y).T.dot(X)\n", |
| 256 | + " grad = (1.0 / n )* (sigmoid(x_dot_weights) - y).T.dot(X)\n", |
257 | 257 | "\n",
|
258 | 258 | " return grad"
|
259 | 259 | ]
|
|
463 | 463 | " I/P\n",
|
464 | 464 | " ----------\n",
|
465 | 465 | " X : 2D array where each row represent the training example and each column represent the feature ndarray. \n",
|
466 |
| - " Dimension(m x n)\n", |
467 |
| - " m= number of training examples\n", |
468 |
| - " n= number of features (including X_0 column of ones)\n", |
| 466 | + " Dimension(n x d)\n", |
| 467 | + " n= number of training examples\n", |
| 468 | + " d= number of features (including X_0 column of ones)\n", |
469 | 469 | "\n",
|
470 | 470 | " theta : 1D array of fitting parameters or weights. Dimension (1 x n)\n",
|
471 | 471 | "\n",
|
|
0 commit comments