Skip to content

Commit 08a264e

Browse files
committed
bh update
1 parent 7ced0fb commit 08a264e

File tree

1 file changed

+71
-24
lines changed

1 file changed

+71
-24
lines changed

projects/boston_housing/boston_housing.ipynb

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@
123123
"- `'LSTAT'` is the percentage of homeowners in the neighborhood considered \"lower class\" (working poor).\n",
124124
"- `'PTRATIO'` is the ratio of students to teachers in primary and secondary schools in the neighborhood.\n",
125125
"\n",
126-
"_Using your intuition, for each of the three features above, do you think that an increase in the value of that feature would lead to an **increase** in the value of `'MEDV'` or a **decrease** in the value of `'MEDV'`? Justify your answer for each._ \n",
127-
"**Hint:** Would you expect a home that has an `'RM'` value of 6 be worth more or less than a home that has an `'RM'` value of 7?"
126+
"\n",
127+
"** Using your intuition, for each of the three features above, do you think that an increase in the value of that feature would lead to an **increase** in the value of `'MEDV'` or a **decrease** in the value of `'MEDV'`? Justify your answer for each.**\n",
128+
"\n",
129+
"**Hint:** This problem can phrased using examples like below. \n",
130+
"* Would you expect a home that has an `'RM'` value(number of rooms) of 6 be worth more or less than a home that has an `'RM'` value of 7?\n",
131+
"* Would you expect a neighborhood that has an `'LSTAT'` value(percent of lower class workers) of 15 have home prices be worth more or less than a neighborhood that has an `'LSTAT'` value of 20?\n",
132+
"* Would you expect a neighborhood that has an `'PTRATIO'` value(ratio of students to teachers) of 10 have home prices be worth more or less than a neighborhood that has an `'PTRATIO'` value of 15?"
128133
]
129134
},
130135
{
@@ -193,7 +198,6 @@
193198
"| 2.0 | 2.1 |\n",
194199
"| 7.0 | 7.8 |\n",
195200
"| 4.2 | 5.3 |\n",
196-
"*Would you consider this model to have successfully captured the variation of the target variable? Why or why not?* \n",
197201
"\n",
198202
"Run the code cell below to use the `performance_metric` function and calculate this model's coefficient of determination."
199203
]
@@ -211,6 +215,20 @@
211215
"print \"Model has a coefficient of determination, R^2, of {:.3f}.\".format(score)"
212216
]
213217
},
218+
{
219+
"cell_type": "markdown",
220+
"metadata": {},
221+
"source": [
222+
"* Would you consider this model to have successfully captured the variation of the target variable? \n",
223+
"* Why or why not?\n",
224+
"\n",
225+
"** Hint: ** The R2 score is the proportion of the variance in the dependent variable that is predictable from the independent variable. In other words:\n",
226+
"* R2 score of 0 means that the dependent variable cannot be predicted from the independent variable.\n",
227+
"* R2 score of 1 means the dependent variable can be predicted from the independent variable.\n",
228+
"* R2 score between 0 and 1 indicates the extent to which the dependent variable is predictable. An \n",
229+
"* R2 score of 0.40 means that 40 percent of the variance in Y is predictable from X."
230+
]
231+
},
214232
{
215233
"cell_type": "markdown",
216234
"metadata": {},
@@ -254,8 +272,10 @@
254272
"metadata": {},
255273
"source": [
256274
"### Question 3 - Training and Testing\n",
257-
"*What is the benefit to splitting a dataset into some ratio of training and testing subsets for a learning algorithm?* \n",
258-
"**Hint:** What could go wrong with not having a way to test your model?"
275+
"\n",
276+
"* What is the benefit to splitting a dataset into some ratio of training and testing subsets for a learning algorithm?\n",
277+
"\n",
278+
"**Hint:** Think about how overfitting or underfitting is contingent upon how splits on data is done."
259279
]
260280
},
261281
{
@@ -303,8 +323,12 @@
303323
"metadata": {},
304324
"source": [
305325
"### Question 4 - Learning the Data\n",
306-
"*Choose one of the graphs above and state the maximum depth for the model. What happens to the score of the training curve as more training points are added? What about the testing curve? Would having more training points benefit the model?* \n",
307-
"**Hint:** Are the learning curves converging to particular scores?"
326+
"* Choose one of the graphs above and state the maximum depth for the model. \n",
327+
"* What happens to the score of the training curve as more training points are added? What about the testing curve? \n",
328+
"* Would having more training points benefit the model? \n",
329+
"\n",
330+
"**Hint:** Are the learning curves converging to particular scores? Generally speaking, the more data you have, the better. But if your training and testing curves are converging with a score above your benchmark threshold, would this be necessary?\n",
331+
"Think about the pros and cons of adding more training points based on if the training and testing curves are converging."
308332
]
309333
},
310334
{
@@ -321,7 +345,7 @@
321345
"### Complexity Curves\n",
322346
"The following code cell produces a graph for a decision tree model that has been trained and validated on the training data using different maximum depths. The graph produces two complexity curves — one for training and one for validation. Similar to the **learning curves**, the shaded regions of both the complexity curves denote the uncertainty in those curves, and the model is scored on both the training and validation sets using the `performance_metric` function. \n",
323347
"\n",
324-
"Run the code cell below and use this graph to answer the following two questions."
348+
"** Run the code cell below and use this graph to answer the following two questions Q5 and Q6. **"
325349
]
326350
},
327351
{
@@ -340,8 +364,10 @@
340364
"metadata": {},
341365
"source": [
342366
"### Question 5 - Bias-Variance Tradeoff\n",
343-
"*When the model is trained with a maximum depth of 1, does the model suffer from high bias or from high variance? How about when the model is trained with a maximum depth of 10? What visual cues in the graph justify your conclusions?* \n",
344-
"**Hint:** How do you know when a model is suffering from high bias or high variance?"
367+
"* When the model is trained with a maximum depth of 1, does the model suffer from high bias or from high variance? \n",
368+
"* How about when the model is trained with a maximum depth of 10? What visual cues in the graph justify your conclusions?\n",
369+
"\n",
370+
"**Hint:** High bias is a sign of underfitting(model is not complex enough to pick up the nuances in the data) and high variance is a sign of overfitting(model is by-hearting the data and cannot generalize well). Think about which model(depth 1 or 10) aligns with which part of the tradeoff."
345371
]
346372
},
347373
{
@@ -356,7 +382,10 @@
356382
"metadata": {},
357383
"source": [
358384
"### Question 6 - Best-Guess Optimal Model\n",
359-
"*Which maximum depth do you think results in a model that best generalizes to unseen data? What intuition lead you to this answer?*"
385+
"* Which maximum depth do you think results in a model that best generalizes to unseen data? \n",
386+
"* What intuition lead you to this answer?\n",
387+
"\n",
388+
"** Hint: ** Look at the graph above Question 5 and see where the validation scores lie for the various depths that have been assigned to the model. Does it get better with increased depth? At what point do we get our best validation score without overcomplicating our model? And remember, Occams Razor states \"Among competing hypotheses, the one with the fewest assumptions should be selected.\""
360389
]
361390
},
362391
{
@@ -381,7 +410,10 @@
381410
"metadata": {},
382411
"source": [
383412
"### Question 7 - Grid Search\n",
384-
"*What is the grid search technique and how it can be applied to optimize a learning algorithm?*"
413+
"* What is the grid search technique?\n",
414+
"* How it can be applied to optimize a learning algorithm?\n",
415+
"\n",
416+
"** Hint: ** When explaining the Grid Search technique, be sure to touch upon why it is used, what the 'grid' entails and what the end goal of this method is. To solidify your answer, you can also give an example of a parameter in a model that can be optimized using this approach."
385417
]
386418
},
387419
{
@@ -401,7 +433,9 @@
401433
"\n",
402434
"* What benefit does this technique provide for grid search when optimizing a model?\n",
403435
"\n",
404-
"**Hint:** When explaining the k-fold cross validation technique, be sure to touch upon how the dataset is split into different parts and how the various parts are used for training and testing. When thinking about how k-fold cross validation helps grid search, think about the main drawbacks of grid search and how k-fold cv could help alleviate that. You can refer to the [docs](http://scikit-learn.org/stable/modules/cross_validation.html#cross-validation) for your answer."
436+
"**Hint:** When explaining the k-fold cross validation technique, be sure to touch upon what 'k' is, how the dataset is split into different parts for training and testing and the number of times it is run based on the 'k' value.\n",
437+
"\n",
438+
"When thinking about how k-fold cross validation helps grid search, think about the main drawbacks of grid search which are hinged upon **using a particular subset of data for training or testing** and how k-fold cv could help alleviate that. You can refer to the [docs](http://scikit-learn.org/stable/modules/cross_validation.html#cross-validation) for your answer."
405439
]
406440
},
407441
{
@@ -461,7 +495,9 @@
461495
" # TODO: Transform 'performance_metric' into a scoring function using 'make_scorer' \n",
462496
" scoring_fnc = None\n",
463497
"\n",
464-
" # TODO: Create the grid search object\n",
498+
" # TODO: Create the grid search cv object --> GridSearchCV()\n",
499+
" # Make sure to include the right parameters in the object:\n",
500+
" # (estimator, param_grid, scoring, cv) which have values 'regressor', 'params', 'scoring_fnc', and 'cv_sets' respectively.\n",
465501
" grid = None\n",
466502
"\n",
467503
" # Fit the grid search object to the data to compute the optimal model\n",
@@ -484,7 +520,8 @@
484520
"metadata": {},
485521
"source": [
486522
"### Question 9 - Optimal Model\n",
487-
"_What maximum depth does the optimal model have? How does this result compare to your guess in **Question 6**?_ \n",
523+
"\n",
524+
"* What maximum depth does the optimal model have? How does this result compare to your guess in **Question 6**? \n",
488525
"\n",
489526
"Run the code block below to fit the decision tree regressor to the training data and produce an optimal model."
490527
]
@@ -509,6 +546,8 @@
509546
"cell_type": "markdown",
510547
"metadata": {},
511548
"source": [
549+
"** Hint: ** The answer comes from the output of the code snipped above.\n",
550+
"\n",
512551
"**Answer: **"
513552
]
514553
},
@@ -524,8 +563,11 @@
524563
"| Total number of rooms in home | 5 rooms | 4 rooms | 8 rooms |\n",
525564
"| Neighborhood poverty level (as %) | 17% | 32% | 3% |\n",
526565
"| Student-teacher ratio of nearby schools | 15-to-1 | 22-to-1 | 12-to-1 |\n",
527-
"*What price would you recommend each client sell his/her home at? Do these prices seem reasonable given the values for the respective features?* \n",
528-
"**Hint:** Use the statistics you calculated in the **Data Exploration** section to help justify your response. \n",
566+
"\n",
567+
"* What price would you recommend each client sell his/her home at? \n",
568+
"* Do these prices seem reasonable given the values for the respective features? \n",
569+
"\n",
570+
"**Hint:** Use the statistics you calculated in the **Data Exploration** section to help justify your response. Of the three clients, client 3 has has the biggest house, in the best public school neighborhood with the lowest poverty level; while client 2 has the smallest house, in a neighborhood with a relatively high poverty rate and not the best public schools.\n",
529571
"\n",
530572
"Run the code block below to have your optimized model make predictions for each client's home."
531573
]
@@ -560,7 +602,9 @@
560602
"metadata": {},
561603
"source": [
562604
"### Sensitivity\n",
563-
"An optimal model is not necessarily a robust model. Sometimes, a model is either too complex or too simple to sufficiently generalize to new data. Sometimes, a model could use a learning algorithm that is not appropriate for the structure of the data given. Other times, the data itself could be too noisy or contain too few samples to allow a model to adequately capture the target variable — i.e., the model is underfitted. Run the code cell below to run the `fit_model` function ten times with different training and testing sets to see how the prediction for a specific client changes with the data it's trained on."
605+
"An optimal model is not necessarily a robust model. Sometimes, a model is either too complex or too simple to sufficiently generalize to new data. Sometimes, a model could use a learning algorithm that is not appropriate for the structure of the data given. Other times, the data itself could be too noisy or contain too few samples to allow a model to adequately capture the target variable — i.e., the model is underfitted. \n",
606+
"\n",
607+
"**Run the code cell below to run the `fit_model` function ten times with different training and testing sets to see how the prediction for a specific client changes with respect to the data it's trained on.**"
564608
]
565609
},
566610
{
@@ -579,12 +623,15 @@
579623
"metadata": {},
580624
"source": [
581625
"### Question 11 - Applicability\n",
582-
"*In a few sentences, discuss whether the constructed model should or should not be used in a real-world setting.* \n",
583-
"**Hint:** Some questions to answering:\n",
584-
"- *How relevant today is data that was collected from 1978?*\n",
585-
"- *Are the features present in the data sufficient to describe a home?*\n",
586-
"- *Is the model robust enough to make consistent predictions?*\n",
587-
"- *Would data collected in an urban city like Boston be applicable in a rural city?*"
626+
"\n",
627+
"* In a few sentences, discuss whether the constructed model should or should not be used in a real-world setting. \n",
628+
"\n",
629+
"**Hint:** Take a look at the range in prices as calculated in the code snippet above. Some questions to answering:\n",
630+
"- How relevant today is data that was collected from 1978? How important is inflation?\n",
631+
"- Are the features present in the data sufficient to describe a home? Do you think factors like quality of apppliances in the home, square feet of the plot area, presence of pool or not etc should factor in?\n",
632+
"- Is the model robust enough to make consistent predictions?\n",
633+
"- Would data collected in an urban city like Boston be applicable in a rural city?\n",
634+
"- Is it fair to judge the price of an individual home based on the characteristics of the entire neighborhood?"
588635
]
589636
},
590637
{

0 commit comments

Comments
 (0)