hidden cell
hidden cell
# Write and run code here
hidden cell
hidden cell
# Write and run code here
hidden cell
# Write and run code here
age sex cp trestbps chol fbs restecg thalach exang oldpeak \
0 52 1 0 125 212 0 1 168 0 1.0
1 53 1 0 140 203 1 0 155 1 3.1
2 70 1 0 145 174 0 1 125 1 2.6
3 61 1 0 148 203 0 1 161 0 0.0
4 62 0 0 138 294 1 1 106 0 1.9
... ... ... .. ... ... ... ... ... ... ...
1020 59 1 1 140 221 0 1 164 1 0.0
1021 60 1 0 125 258 0 0 141 1 2.8
1022 47 1 0 110 275 0 0 118 1 1.0
1023 50 0 0 110 254 0 0 159 0 0.0
1024 54 1 0 120 188 0 1 113 0 1.4
slope ca thal target
0 2 2 3 0
1 0 0 3 0
2 0 0 3 0
3 2 1 3 0
4 1 3 2 0
... ... .. ... ...
1020 2 0 2 1
1021 1 1 3 0
1022 1 1 2 0
1023 2 0 2 1
1024 1 1 3 0
[1025 rows x 14 columns]
hidden cell
# Write and run code here
age [52 53 70 61 62 58 55 46 54 71 43 34 51 50 60 67 45 63 42 44 56 57 59 64
65 41 66 38 49 48 29 37 47 68 76 40 39 77 69 35 74]
sex [1 0]
cp [0 1 2 3]
trestbps [125 140 145 148 138 100 114 160 120 122 112 132 118 128 124 106 104 135
130 136 180 129 150 178 146 117 152 154 170 134 174 144 108 123 110 142
126 192 115 94 200 165 102 105 155 172 164 156 101]
chol [212 203 174 294 248 318 289 249 286 149 341 210 298 204 308 266 244 211
185 223 208 252 209 307 233 319 256 327 169 131 269 196 231 213 271 263
229 360 258 330 342 226 228 278 230 283 241 175 188 217 193 245 232 299
288 197 315 215 164 326 207 177 257 255 187 201 220 268 267 236 303 282
126 309 186 275 281 206 335 218 254 295 417 260 240 302 192 225 325 235
274 234 182 167 172 321 300 199 564 157 304 222 184 354 160 247 239 246
409 293 180 250 221 200 227 243 311 261 242 205 306 219 353 198 394 183
237 224 265 313 340 259 270 216 264 276 322 214 273 253 176 284 305 168
407 290 277 262 195 166 178 141]
fbs [0 1]
restecg [1 0 2]
thalach [168 155 125 161 106 122 140 145 144 116 136 192 156 142 109 162 165 148
172 173 146 179 152 117 115 112 163 147 182 105 150 151 169 166 178 132
160 123 139 111 180 164 202 157 159 170 138 175 158 126 143 141 167 95
190 118 103 181 108 177 134 120 171 149 154 153 88 174 114 195 133 96
124 131 185 194 128 127 186 184 188 130 71 137 99 121 187 97 90 129
113]
exang [0 1]
oldpeak [1. 3.1 2.6 0. 1.9 4.4 0.8 3.2 1.6 3. 0.7 4.2 1.5 2.2 1.1 0.3 0.4 0.6
3.4 2.8 1.2 2.9 3.6 1.4 0.2 2. 5.6 0.9 1.8 6.2 4. 2.5 0.5 0.1 2.1 2.4
3.8 2.3 1.3 3.5]
slope [2 0 1]
ca [2 0 1 3 4]
thal [3 2 1 0]
target [0 1]
hidden cell
hidden cell
# Write and run code here
Correlation between target and target is 1.0
Correlation between oldpeak and target is 0.4384412701119449
Correlation between exang and target is 0.438028550055846
Correlation between cp and target is 0.434854250052737
Correlation between thalach and target is 0.4228954964828723
Correlation between ca and target is 0.3820852890386709
Correlation between slope and target is 0.3455117514359986
Correlation between thal and target is 0.3378381504571859
Correlation between sex and target is 0.2795007572922624
Correlation between age and target is 0.22932355126761092
Correlation between trestbps and target is 0.13877173373730078
Correlation between restecg and target is 0.13446820873908916
Correlation between chol and target is 0.09996559423254128
Correlation between fbs and target is 0.041163547464651236
hidden cell
hidden cell
# Write and run code here
Chi-square test for chol:
Chi-square statistic: 597.1386241903112
P-value: 2.4633681973819975e-54
Degrees of freedom: 151
Chi-square test for fbs:
Chi-square statistic: 1.5133794801852827
P-value: 0.21862413102893974
Degrees of freedom: 1
hidden cell
hidden cell
# Write and run code here
hidden cell
# Write and run code here
age sex cp trestbps fbs restecg thalach exang oldpeak slope \
0 52 1 0 125 0 1 168 0 1.0 2
1 53 1 0 140 1 0 155 1 3.1 0
2 70 1 0 145 0 1 125 1 2.6 0
3 61 1 0 148 0 1 161 0 0.0 2
4 62 0 0 138 1 1 106 0 1.9 1
... ... ... .. ... ... ... ... ... ... ...
1020 59 1 1 140 0 1 164 1 0.0 2
1021 60 1 0 125 0 0 141 1 2.8 1
1022 47 1 0 110 0 0 118 1 1.0 1
1023 50 0 0 110 0 0 159 0 0.0 2
1024 54 1 0 120 0 1 113 0 1.4 1
ca thal target
0 2 3 0
1 0 3 0
2 0 3 0
3 1 3 0
4 3 2 0
... .. ... ...
1020 0 2 1
1021 1 3 0
1022 1 2 0
1023 0 2 1
1024 1 3 0
[1025 rows x 13 columns]
hidden cell
hidden cell
hidden cell
# Write and run code here
hidden cell
# Write and run code here
hidden cell
# Write and run code here
(820, 12) (820,) (205, 12) (205,)
hidden cell
hidden cell
# Write and run code here
hidden cell
# Write and run code here
GridSearchCV(cv=5, estimator=RandomForestClassifier(random_state=42),
param_grid={'max_depth': [None, 5, 10],
'min_samples_leaf': [1, 2, 4],
'min_samples_split': [2, 5, 10],
'n_estimators': [100, 200, 300]},
scoring='f1')
hidden cell
# Write and run code here
hidden cell
# Write and run code here
hidden cell
# Write and run code here
Best parameters found by GridSearchCV: {'max_depth': None, 'min_samples_leaf': 1, 'min_samples_split': 2, 'n_estimators': 100}
Best F1 score found by GridSearchCV: 0.9916310236669517
F1 score on the testing data: 1.0
hidden cell