Skip to content

Commit 28c5dc0

Browse files
committed
T7-1 Arreglado
1 parent dac368a commit 28c5dc0

2 files changed

Lines changed: 30 additions & 319 deletions

File tree

notebooks/T7 - 1 - Trees - Árboles de Decisión-Colab.ipynb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@
142142
"metadata": {},
143143
"outputs": [],
144144
"source": [
145-
"data[\"is_train\"] = (data[\"is_train\"].astype(np.float32) - data[\"is_train\"].astype(np.float32)).astype(np.bool)\n",
146-
"plt.hist(data.is_train)"
145+
"plt.hist(data[\"is_train\"].astype(np.int))"
147146
]
148147
},
149148
{
@@ -216,7 +215,7 @@
216215
},
217216
"outputs": [],
218217
"source": [
219-
"with open(\"/content/python-ml-course/resources/iris_dtree.dot\", \"w\") as dotfile:\n",
218+
"with open(\"/content/python-ml-course/notebooks/resources/iris_dtree.dot\", \"w\") as dotfile:\n",
220219
" export_graphviz(tree, out_file=dotfile, feature_names=predictors)\n",
221220
" dotfile.close()"
222221
]
@@ -239,7 +238,7 @@
239238
},
240239
"outputs": [],
241240
"source": [
242-
"file = open(\"/content/python-ml-course/resources/iris_dtree.dot\", \"r\")\n",
241+
"file = open(\"/content/python-ml-course/notebooks/resources/iris_dtree.dot\", \"r\")\n",
243242
"text = file.read()\n",
244243
"text"
245244
]
@@ -286,7 +285,7 @@
286285
"metadata": {},
287286
"outputs": [],
288287
"source": [
289-
"from sklearn.cross_validation import KFold"
288+
"from sklearn.model_selection import KFold"
290289
]
291290
},
292291
{
@@ -295,16 +294,18 @@
295294
"metadata": {},
296295
"outputs": [],
297296
"source": [
298-
"cv = KFold(n = X.shape[0], n_folds=10, shuffle=True, random_state=1)"
297+
"cv = KFold(n_splits=10, shuffle=True, random_state=1)\n",
298+
"cv.get_n_splits(X)"
299299
]
300300
},
301301
{
302302
"cell_type": "code",
303-
"execution_count": null,
303+
"execution_count": 1,
304304
"metadata": {},
305305
"outputs": [],
306306
"source": [
307-
"from sklearn.cross_validation import cross_val_score"
307+
"from sklearn.model_selection import cross_val_score\n",
308+
"from sklearn.metrics import accuracy_score, make_scorer"
308309
]
309310
},
310311
{
@@ -313,7 +314,7 @@
313314
"metadata": {},
314315
"outputs": [],
315316
"source": [
316-
"scores = cross_val_score(tree, X, Y, scoring=\"accuracy\", cv = cv, n_jobs=1)\n",
317+
"scores = cross_val_score(tree, X, Y, scoring=make_scorer(accuracy_score), cv = cv, n_jobs=1)\n",
317318
"scores"
318319
]
319320
},
@@ -336,8 +337,9 @@
336337
"for i in range(1,11):\n",
337338
" tree = DecisionTreeClassifier(criterion=\"entropy\", max_depth=i, min_samples_split=20, random_state=99)\n",
338339
" tree.fit(X,Y)\n",
339-
" cv = KFold(n = X.shape[0], n_folds=10, shuffle=True, random_state=1)\n",
340-
" scores = cross_val_score(tree, X, Y, scoring=\"accuracy\", cv = cv, n_jobs=1)\n",
340+
" cv = KFold(n_splits=10, shuffle=True, random_state=1)\n",
341+
" cv.get_n_splits(X)\n",
342+
" scores = cross_val_score(tree, X, Y, scoring=\"accuracy\", cv = cv, n_jobs=-1)\n",
341343
" score = np.mean(scores)\n",
342344
" print(\"Score para i = \",i,\" es de \", score)\n",
343345
" print(\" \",tree.feature_importances_)"
@@ -374,7 +376,7 @@
374376
"metadata": {},
375377
"outputs": [],
376378
"source": [
377-
"forest = RandomForestClassifier(n_jobs=2, oob_score=True, n_estimators=100)\n",
379+
"forest = RandomForestClassifier(n_jobs=-1, oob_score=True, n_estimators=100)\n",
378380
"forest.fit(X,Y)"
379381
]
380382
},

0 commit comments

Comments
 (0)