correction to code

This commit is contained in:
mhjensen
2019-11-07 14:28:20 +01:00
parent 31eea8bbeb
commit 7aa82d944e
20 changed files with 185 additions and 297 deletions
@@ -255,29 +255,19 @@ ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">&quot;SAMME.R&quot;</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
ada_clf<span style="color: #666666">.</span>fit(X_train, y_train)
plot_decision_boundary(ada_clf, X, y)
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> AdaBoostClassifier
m <span style="color: #666666">=</span> <span style="color: #008000">len</span>(X_train)
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
<span style="color: #008000; font-weight: bold">for</span> subplot, learning_rate <span style="color: #AA22FF; font-weight: bold">in</span> ((<span style="color: #666666">121</span>, <span style="color: #666666">1</span>), (<span style="color: #666666">122</span>, <span style="color: #666666">0.5</span>)):
sample_weights <span style="color: #666666">=</span> np<span style="color: #666666">.</span>ones(m)
plt<span style="color: #666666">.</span>subplot(subplot)
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">5</span>):
svm_clf <span style="color: #666666">=</span> SVC(kernel<span style="color: #666666">=</span><span style="color: #BA2121">&quot;rbf&quot;</span>, C<span style="color: #666666">=0.05</span>, gamma<span style="color: #666666">=</span><span style="color: #BA2121">&quot;auto&quot;</span>, random_state<span style="color: #666666">=42</span>)
svm_clf<span style="color: #666666">.</span>fit(X_train, y_train, sample_weight<span style="color: #666666">=</span>sample_weights)
y_pred <span style="color: #666666">=</span> svm_clf<span style="color: #666666">.</span>predict(X_train)
sample_weights[y_pred <span style="color: #666666">!=</span> y_train] <span style="color: #666666">*=</span> (<span style="color: #666666">1</span> <span style="color: #666666">+</span> learning_rate)
plot_decision_boundary(svm_clf, X, y, alpha<span style="color: #666666">=0.2</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">&quot;learning_rate = {}&quot;</span><span style="color: #666666">.</span>format(learning_rate), fontsize<span style="color: #666666">=16</span>)
<span style="color: #008000; font-weight: bold">if</span> subplot <span style="color: #666666">==</span> <span style="color: #666666">121</span>:
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.7</span>, <span style="color: #666666">-0.65</span>, <span style="color: #BA2121">&quot;1&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.6</span>, <span style="color: #666666">-0.10</span>, <span style="color: #BA2121">&quot;2&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.5</span>, <span style="color: #666666">0.10</span>, <span style="color: #BA2121">&quot;3&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.4</span>, <span style="color: #666666">0.55</span>, <span style="color: #BA2121">&quot;4&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.3</span>, <span style="color: #666666">0.90</span>, <span style="color: #BA2121">&quot;5&quot;</span>, fontsize<span style="color: #666666">=14</span>)
save_fig(<span style="color: #BA2121">&quot;boosting_plot&quot;</span>)
ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
DecisionTreeClassifier(max_depth<span style="color: #666666">=1</span>), n_estimators<span style="color: #666666">=200</span>,
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">&quot;SAMME.R&quot;</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
ada_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
y_pred <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict(X_test_scaled)
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
plt<span style="color: #666666">.</span>show()
y_probas <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
plt<span style="color: #666666">.</span>show()
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
@@ -2169,29 +2169,19 @@ ada_clf = AdaBoostClassifier(
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
ada_clf.fit(X_train, y_train)
plot_decision_boundary(ada_clf, X, y)
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.ensemble</span> <span style="color: #8B008B; font-weight: bold">import</span> AdaBoostClassifier
m = <span style="color: #658b00">len</span>(X_train)
plt.figure(figsize=(<span style="color: #B452CD">11</span>, <span style="color: #B452CD">4</span>))
<span style="color: #8B008B; font-weight: bold">for</span> subplot, learning_rate <span style="color: #8B008B">in</span> ((<span style="color: #B452CD">121</span>, <span style="color: #B452CD">1</span>), (<span style="color: #B452CD">122</span>, <span style="color: #B452CD">0.5</span>)):
sample_weights = np.ones(m)
plt.subplot(subplot)
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">5</span>):
svm_clf = SVC(kernel=<span style="color: #CD5555">&quot;rbf&quot;</span>, C=<span style="color: #B452CD">0.05</span>, gamma=<span style="color: #CD5555">&quot;auto&quot;</span>, random_state=<span style="color: #B452CD">42</span>)
svm_clf.fit(X_train, y_train, sample_weight=sample_weights)
y_pred = svm_clf.predict(X_train)
sample_weights[y_pred != y_train] *= (<span style="color: #B452CD">1</span> + learning_rate)
plot_decision_boundary(svm_clf, X, y, alpha=<span style="color: #B452CD">0.2</span>)
plt.title(<span style="color: #CD5555">&quot;learning_rate = {}&quot;</span>.format(learning_rate), fontsize=<span style="color: #B452CD">16</span>)
<span style="color: #8B008B; font-weight: bold">if</span> subplot == <span style="color: #B452CD">121</span>:
plt.text(-<span style="color: #B452CD">0.7</span>, -<span style="color: #B452CD">0.65</span>, <span style="color: #CD5555">&quot;1&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.6</span>, -<span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;2&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;3&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.4</span>, <span style="color: #B452CD">0.55</span>, <span style="color: #CD5555">&quot;4&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.3</span>, <span style="color: #B452CD">0.90</span>, <span style="color: #CD5555">&quot;5&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
save_fig(<span style="color: #CD5555">&quot;boosting_plot&quot;</span>)
ada_clf = AdaBoostClassifier(
DecisionTreeClassifier(max_depth=<span style="color: #B452CD">1</span>), n_estimators=<span style="color: #B452CD">200</span>,
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
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=<span style="color: #658b00">True</span>)
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()
</pre></div>
</section>
@@ -2153,29 +2153,19 @@ ada_clf = AdaBoostClassifier(
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
ada_clf.fit(X_train, y_train)
plot_decision_boundary(ada_clf, X, y)
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.ensemble</span> <span style="color: #8B008B; font-weight: bold">import</span> AdaBoostClassifier
m = <span style="color: #658b00">len</span>(X_train)
plt.figure(figsize=(<span style="color: #B452CD">11</span>, <span style="color: #B452CD">4</span>))
<span style="color: #8B008B; font-weight: bold">for</span> subplot, learning_rate <span style="color: #8B008B">in</span> ((<span style="color: #B452CD">121</span>, <span style="color: #B452CD">1</span>), (<span style="color: #B452CD">122</span>, <span style="color: #B452CD">0.5</span>)):
sample_weights = np.ones(m)
plt.subplot(subplot)
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">5</span>):
svm_clf = SVC(kernel=<span style="color: #CD5555">&quot;rbf&quot;</span>, C=<span style="color: #B452CD">0.05</span>, gamma=<span style="color: #CD5555">&quot;auto&quot;</span>, random_state=<span style="color: #B452CD">42</span>)
svm_clf.fit(X_train, y_train, sample_weight=sample_weights)
y_pred = svm_clf.predict(X_train)
sample_weights[y_pred != y_train] *= (<span style="color: #B452CD">1</span> + learning_rate)
plot_decision_boundary(svm_clf, X, y, alpha=<span style="color: #B452CD">0.2</span>)
plt.title(<span style="color: #CD5555">&quot;learning_rate = {}&quot;</span>.format(learning_rate), fontsize=<span style="color: #B452CD">16</span>)
<span style="color: #8B008B; font-weight: bold">if</span> subplot == <span style="color: #B452CD">121</span>:
plt.text(-<span style="color: #B452CD">0.7</span>, -<span style="color: #B452CD">0.65</span>, <span style="color: #CD5555">&quot;1&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.6</span>, -<span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;2&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;3&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.4</span>, <span style="color: #B452CD">0.55</span>, <span style="color: #CD5555">&quot;4&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.3</span>, <span style="color: #B452CD">0.90</span>, <span style="color: #CD5555">&quot;5&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
save_fig(<span style="color: #CD5555">&quot;boosting_plot&quot;</span>)
ada_clf = AdaBoostClassifier(
DecisionTreeClassifier(max_depth=<span style="color: #B452CD">1</span>), n_estimators=<span style="color: #B452CD">200</span>,
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
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=<span style="color: #658b00">True</span>)
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()
</pre></div>
<p>
+12 -22
View File
@@ -2158,29 +2158,19 @@ ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">&quot;SAMME.R&quot;</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
ada_clf<span style="color: #666666">.</span>fit(X_train, y_train)
plot_decision_boundary(ada_clf, X, y)
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> AdaBoostClassifier
m <span style="color: #666666">=</span> <span style="color: #008000">len</span>(X_train)
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
<span style="color: #008000; font-weight: bold">for</span> subplot, learning_rate <span style="color: #AA22FF; font-weight: bold">in</span> ((<span style="color: #666666">121</span>, <span style="color: #666666">1</span>), (<span style="color: #666666">122</span>, <span style="color: #666666">0.5</span>)):
sample_weights <span style="color: #666666">=</span> np<span style="color: #666666">.</span>ones(m)
plt<span style="color: #666666">.</span>subplot(subplot)
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">5</span>):
svm_clf <span style="color: #666666">=</span> SVC(kernel<span style="color: #666666">=</span><span style="color: #BA2121">&quot;rbf&quot;</span>, C<span style="color: #666666">=0.05</span>, gamma<span style="color: #666666">=</span><span style="color: #BA2121">&quot;auto&quot;</span>, random_state<span style="color: #666666">=42</span>)
svm_clf<span style="color: #666666">.</span>fit(X_train, y_train, sample_weight<span style="color: #666666">=</span>sample_weights)
y_pred <span style="color: #666666">=</span> svm_clf<span style="color: #666666">.</span>predict(X_train)
sample_weights[y_pred <span style="color: #666666">!=</span> y_train] <span style="color: #666666">*=</span> (<span style="color: #666666">1</span> <span style="color: #666666">+</span> learning_rate)
plot_decision_boundary(svm_clf, X, y, alpha<span style="color: #666666">=0.2</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">&quot;learning_rate = {}&quot;</span><span style="color: #666666">.</span>format(learning_rate), fontsize<span style="color: #666666">=16</span>)
<span style="color: #008000; font-weight: bold">if</span> subplot <span style="color: #666666">==</span> <span style="color: #666666">121</span>:
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.7</span>, <span style="color: #666666">-0.65</span>, <span style="color: #BA2121">&quot;1&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.6</span>, <span style="color: #666666">-0.10</span>, <span style="color: #BA2121">&quot;2&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.5</span>, <span style="color: #666666">0.10</span>, <span style="color: #BA2121">&quot;3&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.4</span>, <span style="color: #666666">0.55</span>, <span style="color: #BA2121">&quot;4&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.3</span>, <span style="color: #666666">0.90</span>, <span style="color: #BA2121">&quot;5&quot;</span>, fontsize<span style="color: #666666">=14</span>)
save_fig(<span style="color: #BA2121">&quot;boosting_plot&quot;</span>)
ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
DecisionTreeClassifier(max_depth<span style="color: #666666">=1</span>), n_estimators<span style="color: #666666">=200</span>,
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">&quot;SAMME.R&quot;</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
ada_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
y_pred <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict(X_test_scaled)
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
plt<span style="color: #666666">.</span>show()
y_probas <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
plt<span style="color: #666666">.</span>show()
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
@@ -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 ;
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 KiB

After

Width:  |  Height:  |  Size: 216 KiB

+12 -22
View File
@@ -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()"
]
},
Binary file not shown.
Binary file not shown.
@@ -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}
+12 -22
View File
@@ -2169,29 +2169,19 @@ ada_clf = AdaBoostClassifier(
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
ada_clf.fit(X_train, y_train)
plot_decision_boundary(ada_clf, X, y)
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.ensemble</span> <span style="color: #8B008B; font-weight: bold">import</span> AdaBoostClassifier
m = <span style="color: #658b00">len</span>(X_train)
plt.figure(figsize=(<span style="color: #B452CD">11</span>, <span style="color: #B452CD">4</span>))
<span style="color: #8B008B; font-weight: bold">for</span> subplot, learning_rate <span style="color: #8B008B">in</span> ((<span style="color: #B452CD">121</span>, <span style="color: #B452CD">1</span>), (<span style="color: #B452CD">122</span>, <span style="color: #B452CD">0.5</span>)):
sample_weights = np.ones(m)
plt.subplot(subplot)
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">5</span>):
svm_clf = SVC(kernel=<span style="color: #CD5555">&quot;rbf&quot;</span>, C=<span style="color: #B452CD">0.05</span>, gamma=<span style="color: #CD5555">&quot;auto&quot;</span>, random_state=<span style="color: #B452CD">42</span>)
svm_clf.fit(X_train, y_train, sample_weight=sample_weights)
y_pred = svm_clf.predict(X_train)
sample_weights[y_pred != y_train] *= (<span style="color: #B452CD">1</span> + learning_rate)
plot_decision_boundary(svm_clf, X, y, alpha=<span style="color: #B452CD">0.2</span>)
plt.title(<span style="color: #CD5555">&quot;learning_rate = {}&quot;</span>.format(learning_rate), fontsize=<span style="color: #B452CD">16</span>)
<span style="color: #8B008B; font-weight: bold">if</span> subplot == <span style="color: #B452CD">121</span>:
plt.text(-<span style="color: #B452CD">0.7</span>, -<span style="color: #B452CD">0.65</span>, <span style="color: #CD5555">&quot;1&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.6</span>, -<span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;2&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;3&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.4</span>, <span style="color: #B452CD">0.55</span>, <span style="color: #CD5555">&quot;4&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.3</span>, <span style="color: #B452CD">0.90</span>, <span style="color: #CD5555">&quot;5&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
save_fig(<span style="color: #CD5555">&quot;boosting_plot&quot;</span>)
ada_clf = AdaBoostClassifier(
DecisionTreeClassifier(max_depth=<span style="color: #B452CD">1</span>), n_estimators=<span style="color: #B452CD">200</span>,
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
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=<span style="color: #658b00">True</span>)
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()
</pre></div>
</section>
@@ -2153,29 +2153,19 @@ ada_clf = AdaBoostClassifier(
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
ada_clf.fit(X_train, y_train)
plot_decision_boundary(ada_clf, X, y)
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.ensemble</span> <span style="color: #8B008B; font-weight: bold">import</span> AdaBoostClassifier
m = <span style="color: #658b00">len</span>(X_train)
plt.figure(figsize=(<span style="color: #B452CD">11</span>, <span style="color: #B452CD">4</span>))
<span style="color: #8B008B; font-weight: bold">for</span> subplot, learning_rate <span style="color: #8B008B">in</span> ((<span style="color: #B452CD">121</span>, <span style="color: #B452CD">1</span>), (<span style="color: #B452CD">122</span>, <span style="color: #B452CD">0.5</span>)):
sample_weights = np.ones(m)
plt.subplot(subplot)
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">5</span>):
svm_clf = SVC(kernel=<span style="color: #CD5555">&quot;rbf&quot;</span>, C=<span style="color: #B452CD">0.05</span>, gamma=<span style="color: #CD5555">&quot;auto&quot;</span>, random_state=<span style="color: #B452CD">42</span>)
svm_clf.fit(X_train, y_train, sample_weight=sample_weights)
y_pred = svm_clf.predict(X_train)
sample_weights[y_pred != y_train] *= (<span style="color: #B452CD">1</span> + learning_rate)
plot_decision_boundary(svm_clf, X, y, alpha=<span style="color: #B452CD">0.2</span>)
plt.title(<span style="color: #CD5555">&quot;learning_rate = {}&quot;</span>.format(learning_rate), fontsize=<span style="color: #B452CD">16</span>)
<span style="color: #8B008B; font-weight: bold">if</span> subplot == <span style="color: #B452CD">121</span>:
plt.text(-<span style="color: #B452CD">0.7</span>, -<span style="color: #B452CD">0.65</span>, <span style="color: #CD5555">&quot;1&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.6</span>, -<span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;2&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">0.10</span>, <span style="color: #CD5555">&quot;3&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.4</span>, <span style="color: #B452CD">0.55</span>, <span style="color: #CD5555">&quot;4&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
plt.text(-<span style="color: #B452CD">0.3</span>, <span style="color: #B452CD">0.90</span>, <span style="color: #CD5555">&quot;5&quot;</span>, fontsize=<span style="color: #B452CD">14</span>)
save_fig(<span style="color: #CD5555">&quot;boosting_plot&quot;</span>)
ada_clf = AdaBoostClassifier(
DecisionTreeClassifier(max_depth=<span style="color: #B452CD">1</span>), n_estimators=<span style="color: #B452CD">200</span>,
algorithm=<span style="color: #CD5555">&quot;SAMME.R&quot;</span>, learning_rate=<span style="color: #B452CD">0.5</span>, random_state=<span style="color: #B452CD">42</span>)
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=<span style="color: #658b00">True</span>)
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()
</pre></div>
<p>
+12 -22
View File
@@ -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
+12 -22
View File
@@ -2158,29 +2158,19 @@ ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">&quot;SAMME.R&quot;</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
ada_clf<span style="color: #666666">.</span>fit(X_train, y_train)
plot_decision_boundary(ada_clf, X, y)
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.ensemble</span> <span style="color: #008000; font-weight: bold">import</span> AdaBoostClassifier
m <span style="color: #666666">=</span> <span style="color: #008000">len</span>(X_train)
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">11</span>, <span style="color: #666666">4</span>))
<span style="color: #008000; font-weight: bold">for</span> subplot, learning_rate <span style="color: #AA22FF; font-weight: bold">in</span> ((<span style="color: #666666">121</span>, <span style="color: #666666">1</span>), (<span style="color: #666666">122</span>, <span style="color: #666666">0.5</span>)):
sample_weights <span style="color: #666666">=</span> np<span style="color: #666666">.</span>ones(m)
plt<span style="color: #666666">.</span>subplot(subplot)
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">5</span>):
svm_clf <span style="color: #666666">=</span> SVC(kernel<span style="color: #666666">=</span><span style="color: #BA2121">&quot;rbf&quot;</span>, C<span style="color: #666666">=0.05</span>, gamma<span style="color: #666666">=</span><span style="color: #BA2121">&quot;auto&quot;</span>, random_state<span style="color: #666666">=42</span>)
svm_clf<span style="color: #666666">.</span>fit(X_train, y_train, sample_weight<span style="color: #666666">=</span>sample_weights)
y_pred <span style="color: #666666">=</span> svm_clf<span style="color: #666666">.</span>predict(X_train)
sample_weights[y_pred <span style="color: #666666">!=</span> y_train] <span style="color: #666666">*=</span> (<span style="color: #666666">1</span> <span style="color: #666666">+</span> learning_rate)
plot_decision_boundary(svm_clf, X, y, alpha<span style="color: #666666">=0.2</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">&quot;learning_rate = {}&quot;</span><span style="color: #666666">.</span>format(learning_rate), fontsize<span style="color: #666666">=16</span>)
<span style="color: #008000; font-weight: bold">if</span> subplot <span style="color: #666666">==</span> <span style="color: #666666">121</span>:
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.7</span>, <span style="color: #666666">-0.65</span>, <span style="color: #BA2121">&quot;1&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.6</span>, <span style="color: #666666">-0.10</span>, <span style="color: #BA2121">&quot;2&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.5</span>, <span style="color: #666666">0.10</span>, <span style="color: #BA2121">&quot;3&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.4</span>, <span style="color: #666666">0.55</span>, <span style="color: #BA2121">&quot;4&quot;</span>, fontsize<span style="color: #666666">=14</span>)
plt<span style="color: #666666">.</span>text(<span style="color: #666666">-0.3</span>, <span style="color: #666666">0.90</span>, <span style="color: #BA2121">&quot;5&quot;</span>, fontsize<span style="color: #666666">=14</span>)
save_fig(<span style="color: #BA2121">&quot;boosting_plot&quot;</span>)
ada_clf <span style="color: #666666">=</span> AdaBoostClassifier(
DecisionTreeClassifier(max_depth<span style="color: #666666">=1</span>), n_estimators<span style="color: #666666">=200</span>,
algorithm<span style="color: #666666">=</span><span style="color: #BA2121">&quot;SAMME.R&quot;</span>, learning_rate<span style="color: #666666">=0.5</span>, random_state<span style="color: #666666">=42</span>)
ada_clf<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
y_pred <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict(X_test_scaled)
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_confusion_matrix(y_test, y_pred, normalize<span style="color: #666666">=</span><span style="color: #008000">True</span>)
plt<span style="color: #666666">.</span>show()
y_probas <span style="color: #666666">=</span> ada_clf<span style="color: #666666">.</span>predict_proba(X_test_scaled)
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_roc(y_test, y_probas)
plt<span style="color: #666666">.</span>show()
skplt<span style="color: #666666">.</span>metrics<span style="color: #666666">.</span>plot_cumulative_gain(y_test, y_probas)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
+12 -22
View File
@@ -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()"
]
},
+12 -22
View File
@@ -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
+12 -22
View File
@@ -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}
@@ -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
Binary file not shown.