You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learntools/intro_to_programming/ex3.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ class CustomEngravings(FunctionProblem):
45
45
(("Adrian", True), 160),
46
46
(("Ana", False), 71),
47
47
]
48
-
_hint= ("There are two options - either the project uses solid gold or does not. With this in mind, you can structure your solution like this: `cost = solid_gold * ____ + (not_solid_gold) * ____`. You need to figure out how to fill in the blanks. Also, remember that:\n"
48
+
_hint= ("There are two options - either the project uses solid gold or does not. With this in mind, you can structure your solution like this: `cost = solid_gold * ____ + (not solid_gold) * ____`. You need to figure out how to fill in the blanks. Also, remember that:\n"
49
49
"- If `solid_gold = True`, then `(not solid_gold) = False`, and if `solid_gold = False`, then `(not solid_gold) = True`.\n"
50
50
"- Multiplying an integer by `True` is equivalent to multiplying it by 1, and multiplying an integer by `False` is equivalent to multiplying it by 0.")
_hint='First find the vertical level corresponding to -74 dropoff longitude. Then read off the horizontal values you are switching between. Use the white contour lines to orient yourself on what values you are near. You can round to the nearest integer rather than stressing about the exact cost to the nearest penny'
54
-
_solution='About \$15. The price decreases from slightly more than \$24 to slightly more than \$9.'
52
+
_hint='First find the vertical level corresponding to -74 dropoff longitude. Then read off the horizontal values you are switching between. Use the contour lines to orient yourself on what values you are near. You can round to the nearest integer rather than stressing about the exact cost to the nearest penny'
53
+
_solution='About 6. The price decreases from slightly less than 15 to slightly less than 9.'
55
54
defcheck(self, savings):
56
55
iftype(savings) ==str:
57
56
savings=Decimal(dollars.strip('$'))
58
-
assert ((savings>13) and (savings<17)), "Your answer should be about 15. Not {}".format(savings)
57
+
assert ((savings>4) and (savings<8)), "Your answer should be about 6. Not {}".format(savings)
59
58
59
+
# 4
60
60
classMakePDPWithAbsFeatures(CodingProblem):
61
-
_var='pdp_dist'
62
-
_hint='use the abs function when creating the abs_lat_change and abs_lon_change features. You don\'t need to change anything else.'
61
+
_var='disp'
62
+
_hint='Use the abs function when creating the abs_lat_change and abs_lon_change features. You don\'t need to change anything else.'
63
63
_solution= \
64
64
"""
65
-
The biggest difference is that the partial dependence plot became much smaller. The the lowest vertical value is about $15 below the highest vertical value in the top chart, whereas this difference is only about $3 in the chart you just created. In other words, once you control for absolute distance traveled, the pickup_longitude has only a very small impact on predictions.
65
+
The difference is that the partial dependence plot became smaller. Both plots have a lowest vertical value of 8.5. But, the highest vertical value in the top chart is around 10.7, and the highest vertical value in the bottom chart is below 9.1. In other words, once you control for absolute distance traveled, the pickup_longitude has a smaller impact on predictions.
_solution="No. This doesn't guarantee `feat_a` is more important. For example, `feat_a` could have a big effect in the cases where it varies, but could have a single value 99\% of the time. In that case, permuting `feat_a` wouldn't matter much, since most values would be unchanged."
80
99
100
+
# 6
81
101
classDesignDatasetUShapedPdp(CodingProblem):
82
-
_var='pdp_dist'
102
+
_var='disp'
83
103
_hint="Consider explicitly using terms that include mathematical expressions like `(X1 < -1)`"
84
104
_solution=CS(
85
105
"""
@@ -89,22 +109,26 @@ class DesignDatasetUShapedPdp(CodingProblem):
_hint="You need for X1 to affect the prediction in order to have it affect permutation importance. But the average effect needs to be 0 to satisfy the PDP requirement. Achieve this by creating an interaction, so the effect of X1 depends on the value of X2 and vice-versa."
109
133
_solution=CS(
110
134
"""
@@ -117,9 +141,10 @@ class DesignFlatPDPWithHighImportance(CodingProblem):
117
141
# Aside from these lines, use the code provided
118
142
""")
119
143
120
-
defcheck(self, importance, pdpResult):
144
+
defcheck(self, importance, disp):
121
145
X1_imp=importance.feature_importances_[0]
122
-
pdpRange=max(pdpResult.pdp) -min(pdpResult.pdp)
146
+
pdpResult=disp.pd_results[0]['average'][0]
147
+
pdpRange=max(pdpResult) -min(pdpResult)
123
148
assert (X1_imp>0.5), ("Tested that X1 has an importance > 0.5. "
124
149
"Actual importance was {}").format(X1_imp)
125
150
assert (pdpRange<0.5), ("Tested that the highest point on the Partial "
0 commit comments