diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs050.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs050.html index b0f46a328..0aaa38ffa 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs050.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs050.html @@ -255,29 +255,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show()
diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html b/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html index 0d1365a1e..375db2cf4 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html @@ -2169,29 +2169,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show() diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html b/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html index 1d6e730c8..be18aa969 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-solarized.html @@ -2153,29 +2153,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show()
diff --git a/doc/pub/DecisionTrees/html/DecisionTrees.html b/doc/pub/DecisionTrees/html/DecisionTrees.html index e66d392b2..ef2e11ccc 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees.html @@ -2158,29 +2158,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show()
diff --git a/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.dot b/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.dot index 4d258be18..394d2c48d 100644 --- a/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.dot +++ b/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.dot @@ -6,15 +6,15 @@ edge [fontname=helvetica] ; 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ; 2 [label="worst concave points <= 0.135\ngini = 0.031\nsamples = 253\nvalue = [[249, 4]\n[4, 249]]", fillcolor="#e58139ee"] ; 1 -> 2 ; -3 [label="radius error <= 0.643\ngini = 0.008\nsamples = 242\nvalue = [[241, 1]\n[1, 241]]", fillcolor="#e58139fb"] ; +3 [label="area error <= 48.975\ngini = 0.008\nsamples = 242\nvalue = [[241, 1]\n[1, 241]]", fillcolor="#e58139fb"] ; 2 -> 3 ; 4 [label="gini = 0.0\nsamples = 239\nvalue = [[239, 0]\n[0, 239]]", fillcolor="#e58139ff"] ; 3 -> 4 ; -5 [label="texture error <= 1.938\ngini = 0.444\nsamples = 3\nvalue = [[2, 1]\n[1, 2]]", fillcolor="#e5813913"] ; +5 [label="mean area <= 469.25\ngini = 0.444\nsamples = 3\nvalue = [[2, 1]\n[1, 2]]", fillcolor="#e5813913"] ; 3 -> 5 ; -6 [label="gini = 0.0\nsamples = 2\nvalue = [[2, 0]\n[0, 2]]", fillcolor="#e58139ff"] ; +6 [label="gini = 0.0\nsamples = 1\nvalue = [[0, 1]\n[1, 0]]", fillcolor="#e58139ff"] ; 5 -> 6 ; -7 [label="gini = 0.0\nsamples = 1\nvalue = [[0, 1]\n[1, 0]]", fillcolor="#e58139ff"] ; +7 [label="gini = 0.0\nsamples = 2\nvalue = [[2, 0]\n[0, 2]]", fillcolor="#e58139ff"] ; 5 -> 7 ; 8 [label="mean texture <= 20.84\ngini = 0.397\nsamples = 11\nvalue = [[8, 3]\n[3, 8]]", fillcolor="#e581392c"] ; 2 -> 8 ; @@ -22,7 +22,7 @@ edge [fontname=helvetica] ; 8 -> 9 ; 10 [label="gini = 0.0\nsamples = 3\nvalue = [[0, 3]\n[3, 0]]", fillcolor="#e58139ff"] ; 8 -> 10 ; -11 [label="area error <= 13.475\ngini = 0.278\nsamples = 6\nvalue = [[1, 5]\n[5, 1]]", fillcolor="#e581396b"] ; +11 [label="worst texture <= 24.785\ngini = 0.278\nsamples = 6\nvalue = [[1, 5]\n[5, 1]]", fillcolor="#e581396b"] ; 1 -> 11 ; 12 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ; 11 -> 12 ; @@ -30,11 +30,11 @@ edge [fontname=helvetica] ; 11 -> 13 ; 14 [label="worst texture <= 20.645\ngini = 0.202\nsamples = 167\nvalue = [[19, 148]\n[148, 19]]", fillcolor="#e5813994"] ; 0 -> 14 [labeldistance=2.5, labelangle=-45, headlabel="False"] ; -15 [label="worst concavity <= 0.318\ngini = 0.375\nsamples = 16\nvalue = [[12, 4]\n[4, 12]]", fillcolor="#e5813938"] ; +15 [label="worst perimeter <= 116.8\ngini = 0.375\nsamples = 16\nvalue = [[12, 4]\n[4, 12]]", fillcolor="#e5813938"] ; 14 -> 15 ; 16 [label="gini = 0.0\nsamples = 11\nvalue = [[11, 0]\n[0, 11]]", fillcolor="#e58139ff"] ; 15 -> 16 ; -17 [label="mean concavity <= 0.07\ngini = 0.32\nsamples = 5\nvalue = [[1, 4]\n[4, 1]]", fillcolor="#e5813955"] ; +17 [label="worst texture <= 18.445\ngini = 0.32\nsamples = 5\nvalue = [[1, 4]\n[4, 1]]", fillcolor="#e5813955"] ; 15 -> 17 ; 18 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ; 17 -> 18 ; @@ -42,16 +42,16 @@ edge [fontname=helvetica] ; 17 -> 19 ; 20 [label="mean concave points <= 0.049\ngini = 0.088\nsamples = 151\nvalue = [[7, 144]\n[144, 7]]", fillcolor="#e58139d0"] ; 14 -> 20 ; -21 [label="compactness error <= 0.016\ngini = 0.48\nsamples = 15\nvalue = [[6, 9]\n[9, 6]]", fillcolor="#e5813900"] ; +21 [label="concave points error <= 0.01\ngini = 0.48\nsamples = 15\nvalue = [[6, 9]\n[9, 6]]", fillcolor="#e5813900"] ; 20 -> 21 ; 22 [label="gini = 0.0\nsamples = 9\nvalue = [[0, 9]\n[9, 0]]", fillcolor="#e58139ff"] ; 21 -> 22 ; 23 [label="gini = 0.0\nsamples = 6\nvalue = [[6, 0]\n[0, 6]]", fillcolor="#e58139ff"] ; 21 -> 23 ; -24 [label="fractal dimension error <= 0.013\ngini = 0.015\nsamples = 136\nvalue = [[1, 135]\n[135, 1]]", fillcolor="#e58139f7"] ; +24 [label="mean smoothness <= 0.079\ngini = 0.015\nsamples = 136\nvalue = [[1, 135]\n[135, 1]]", fillcolor="#e58139f7"] ; 20 -> 24 ; -25 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139ff"] ; +25 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ; 24 -> 25 ; -26 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ; +26 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139ff"] ; 24 -> 26 ; } \ No newline at end of file diff --git a/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.png b/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.png index 98014cc9c..fa20fd0c0 100644 Binary files a/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.png and b/doc/pub/DecisionTrees/ipynb/DataFiles/cancer.png differ diff --git a/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb b/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb index 1161b80b6..0b847eaec 100644 --- a/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb +++ b/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb @@ -2229,29 +2229,19 @@ " algorithm=\"SAMME.R\", learning_rate=0.5, random_state=42)\n", "ada_clf.fit(X_train, y_train)\n", "\n", - "plot_decision_boundary(ada_clf, X, y)\n", + "from sklearn.ensemble import AdaBoostClassifier\n", "\n", - "m = len(X_train)\n", - "\n", - "plt.figure(figsize=(11, 4))\n", - "for subplot, learning_rate in ((121, 1), (122, 0.5)):\n", - " sample_weights = np.ones(m)\n", - " plt.subplot(subplot)\n", - " for i in range(5):\n", - " svm_clf = SVC(kernel=\"rbf\", C=0.05, gamma=\"auto\", random_state=42)\n", - " svm_clf.fit(X_train, y_train, sample_weight=sample_weights)\n", - " y_pred = svm_clf.predict(X_train)\n", - " sample_weights[y_pred != y_train] *= (1 + learning_rate)\n", - " plot_decision_boundary(svm_clf, X, y, alpha=0.2)\n", - " plt.title(\"learning_rate = {}\".format(learning_rate), fontsize=16)\n", - " if subplot == 121:\n", - " plt.text(-0.7, -0.65, \"1\", fontsize=14)\n", - " plt.text(-0.6, -0.10, \"2\", fontsize=14)\n", - " plt.text(-0.5, 0.10, \"3\", fontsize=14)\n", - " plt.text(-0.4, 0.55, \"4\", fontsize=14)\n", - " plt.text(-0.3, 0.90, \"5\", fontsize=14)\n", - "\n", - "save_fig(\"boosting_plot\")\n", + "ada_clf = AdaBoostClassifier(\n", + " DecisionTreeClassifier(max_depth=1), n_estimators=200,\n", + " algorithm=\"SAMME.R\", learning_rate=0.5, random_state=42)\n", + "ada_clf.fit(X_train_scaled, y_train)\n", + "y_pred = ada_clf.predict(X_test_scaled)\n", + "skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)\n", + "plt.show()\n", + "y_probas = ada_clf.predict_proba(X_test_scaled)\n", + "skplt.metrics.plot_roc(y_test, y_probas)\n", + "plt.show()\n", + "skplt.metrics.plot_cumulative_gain(y_test, y_probas)\n", "plt.show()" ] }, diff --git a/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz b/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz index 0ff487d36..1b68e0a76 100644 Binary files a/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz and b/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz differ diff --git a/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf b/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf index 6fc29fb0b..a2cb0e67f 100644 Binary files a/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf and b/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf differ diff --git a/doc/src/DecisionTrees/DecisionTrees-minted.pdf b/doc/src/DecisionTrees/DecisionTrees-minted.pdf index 6fc29fb0b..a2cb0e67f 100644 Binary files a/doc/src/DecisionTrees/DecisionTrees-minted.pdf and b/doc/src/DecisionTrees/DecisionTrees-minted.pdf differ diff --git a/doc/src/DecisionTrees/DecisionTrees-plain-minted.tex b/doc/src/DecisionTrees/DecisionTrees-plain-minted.tex index 5ab09d845..17582a165 100644 --- a/doc/src/DecisionTrees/DecisionTrees-plain-minted.tex +++ b/doc/src/DecisionTrees/DecisionTrees-plain-minted.tex @@ -2065,29 +2065,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show() \end{minted} diff --git a/doc/src/DecisionTrees/DecisionTrees-reveal.html b/doc/src/DecisionTrees/DecisionTrees-reveal.html index 0d1365a1e..375db2cf4 100644 --- a/doc/src/DecisionTrees/DecisionTrees-reveal.html +++ b/doc/src/DecisionTrees/DecisionTrees-reveal.html @@ -2169,29 +2169,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show() diff --git a/doc/src/DecisionTrees/DecisionTrees-solarized.html b/doc/src/DecisionTrees/DecisionTrees-solarized.html index 1d6e730c8..be18aa969 100644 --- a/doc/src/DecisionTrees/DecisionTrees-solarized.html +++ b/doc/src/DecisionTrees/DecisionTrees-solarized.html @@ -2153,29 +2153,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show()
diff --git a/doc/src/DecisionTrees/DecisionTrees.do.txt b/doc/src/DecisionTrees/DecisionTrees.do.txt index cbdaccecb..444de6fc9 100644 --- a/doc/src/DecisionTrees/DecisionTrees.do.txt +++ b/doc/src/DecisionTrees/DecisionTrees.do.txt @@ -1802,29 +1802,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show() !ec diff --git a/doc/src/DecisionTrees/DecisionTrees.html b/doc/src/DecisionTrees/DecisionTrees.html index e66d392b2..ef2e11ccc 100644 --- a/doc/src/DecisionTrees/DecisionTrees.html +++ b/doc/src/DecisionTrees/DecisionTrees.html @@ -2158,29 +2158,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show()
diff --git a/doc/src/DecisionTrees/DecisionTrees.ipynb b/doc/src/DecisionTrees/DecisionTrees.ipynb index 1161b80b6..0b847eaec 100644 --- a/doc/src/DecisionTrees/DecisionTrees.ipynb +++ b/doc/src/DecisionTrees/DecisionTrees.ipynb @@ -2229,29 +2229,19 @@ " algorithm=\"SAMME.R\", learning_rate=0.5, random_state=42)\n", "ada_clf.fit(X_train, y_train)\n", "\n", - "plot_decision_boundary(ada_clf, X, y)\n", + "from sklearn.ensemble import AdaBoostClassifier\n", "\n", - "m = len(X_train)\n", - "\n", - "plt.figure(figsize=(11, 4))\n", - "for subplot, learning_rate in ((121, 1), (122, 0.5)):\n", - " sample_weights = np.ones(m)\n", - " plt.subplot(subplot)\n", - " for i in range(5):\n", - " svm_clf = SVC(kernel=\"rbf\", C=0.05, gamma=\"auto\", random_state=42)\n", - " svm_clf.fit(X_train, y_train, sample_weight=sample_weights)\n", - " y_pred = svm_clf.predict(X_train)\n", - " sample_weights[y_pred != y_train] *= (1 + learning_rate)\n", - " plot_decision_boundary(svm_clf, X, y, alpha=0.2)\n", - " plt.title(\"learning_rate = {}\".format(learning_rate), fontsize=16)\n", - " if subplot == 121:\n", - " plt.text(-0.7, -0.65, \"1\", fontsize=14)\n", - " plt.text(-0.6, -0.10, \"2\", fontsize=14)\n", - " plt.text(-0.5, 0.10, \"3\", fontsize=14)\n", - " plt.text(-0.4, 0.55, \"4\", fontsize=14)\n", - " plt.text(-0.3, 0.90, \"5\", fontsize=14)\n", - "\n", - "save_fig(\"boosting_plot\")\n", + "ada_clf = AdaBoostClassifier(\n", + " DecisionTreeClassifier(max_depth=1), n_estimators=200,\n", + " algorithm=\"SAMME.R\", learning_rate=0.5, random_state=42)\n", + "ada_clf.fit(X_train_scaled, y_train)\n", + "y_pred = ada_clf.predict(X_test_scaled)\n", + "skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)\n", + "plt.show()\n", + "y_probas = ada_clf.predict_proba(X_test_scaled)\n", + "skplt.metrics.plot_roc(y_test, y_probas)\n", + "plt.show()\n", + "skplt.metrics.plot_cumulative_gain(y_test, y_probas)\n", "plt.show()" ] }, diff --git a/doc/src/DecisionTrees/DecisionTrees.p.tex b/doc/src/DecisionTrees/DecisionTrees.p.tex index 1005fdb09..8fb4bec9b 100644 --- a/doc/src/DecisionTrees/DecisionTrees.p.tex +++ b/doc/src/DecisionTrees/DecisionTrees.p.tex @@ -2093,29 +2093,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show() \epycod diff --git a/doc/src/DecisionTrees/DecisionTrees.tex b/doc/src/DecisionTrees/DecisionTrees.tex index 5ab09d845..17582a165 100644 --- a/doc/src/DecisionTrees/DecisionTrees.tex +++ b/doc/src/DecisionTrees/DecisionTrees.tex @@ -2065,29 +2065,19 @@ ada_clf = AdaBoostClassifier( algorithm="SAMME.R", learning_rate=0.5, random_state=42) ada_clf.fit(X_train, y_train) -plot_decision_boundary(ada_clf, X, y) +from sklearn.ensemble import AdaBoostClassifier -m = len(X_train) - -plt.figure(figsize=(11, 4)) -for subplot, learning_rate in ((121, 1), (122, 0.5)): - sample_weights = np.ones(m) - plt.subplot(subplot) - for i in range(5): - svm_clf = SVC(kernel="rbf", C=0.05, gamma="auto", random_state=42) - svm_clf.fit(X_train, y_train, sample_weight=sample_weights) - y_pred = svm_clf.predict(X_train) - sample_weights[y_pred != y_train] *= (1 + learning_rate) - plot_decision_boundary(svm_clf, X, y, alpha=0.2) - plt.title("learning_rate = {}".format(learning_rate), fontsize=16) - if subplot == 121: - plt.text(-0.7, -0.65, "1", fontsize=14) - plt.text(-0.6, -0.10, "2", fontsize=14) - plt.text(-0.5, 0.10, "3", fontsize=14) - plt.text(-0.4, 0.55, "4", fontsize=14) - plt.text(-0.3, 0.90, "5", fontsize=14) - -save_fig("boosting_plot") +ada_clf = AdaBoostClassifier( + DecisionTreeClassifier(max_depth=1), n_estimators=200, + algorithm="SAMME.R", learning_rate=0.5, random_state=42) +ada_clf.fit(X_train_scaled, y_train) +y_pred = ada_clf.predict(X_test_scaled) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = ada_clf.predict_proba(X_test_scaled) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) plt.show() \end{minted} diff --git a/doc/src/DecisionTrees/Programs/xgregressor.py b/doc/src/DecisionTrees/Programs/xgregressor.py index b22184913..6a58b6bf1 100644 --- a/doc/src/DecisionTrees/Programs/xgregressor.py +++ b/doc/src/DecisionTrees/Programs/xgregressor.py @@ -6,6 +6,24 @@ from sklearn.preprocessing import StandardScaler import scikitplot as skplt from sklearn.metrics import mean_squared_error + +def plot_decision_boundary(clf, X, y, axes=[-1.5, 2.5, -1, 1.5], alpha=0.5, contour=True): + x1s = np.linspace(axes[0], axes[1], 100) + x2s = np.linspace(axes[2], axes[3], 100) + x1, x2 = np.meshgrid(x1s, x2s) + X_new = np.c_[x1.ravel(), x2.ravel()] + y_pred = clf.predict(X_new).reshape(x1.shape) + custom_cmap = ListedColormap(['#fafab0','#9898ff','#a0faa0']) + plt.contourf(x1, x2, y_pred, alpha=0.3, cmap=custom_cmap) + if contour: + custom_cmap2 = ListedColormap(['#7d7d58','#4c4c7f','#507d50']) + plt.contour(x1, x2, y_pred, cmap=custom_cmap2, alpha=0.8) + plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo", alpha=alpha) + plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs", alpha=alpha) + plt.axis(axes) + plt.xlabel(r"$x_1$", fontsize=18) + plt.ylabel(r"$x_2$", fontsize=18, rotation=0) + n = 500 maxdegree = 8 diff --git a/doc/src/DecisionTrees/ipynb-DecisionTrees-src.tar.gz b/doc/src/DecisionTrees/ipynb-DecisionTrees-src.tar.gz index 0ff487d36..1b68e0a76 100644 Binary files a/doc/src/DecisionTrees/ipynb-DecisionTrees-src.tar.gz and b/doc/src/DecisionTrees/ipynb-DecisionTrees-src.tar.gz differ