correction to code
This commit is contained in:
@@ -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}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user