Untitled
unknown
plain_text
4 months ago
1.1 kB
3
Indexable
for t in tqdm(range(1, T + 1), desc="Boosting Iterations"): # Step 3.1: Train decision stump feature, theta, s, epsilon = train_decision_stump(X_train, y_train, u) stump_info.append((feature, theta, s)) # Step 3.2: Calculate alpha # alpha = log(sqrt((1 - epsilon) / epsilon)) = log((1 - epsilon) / epsilon)) / 2 alpha = np.log((1 - epsilon) / max(epsilon, 1e-10)) / 2 alpha_values.append(alpha) # Step 3.3: Update weights predictions = s * np.sign(X_train[:, feature] - theta) u = u * np.exp(-alpha * y_train * predictions) U_t.append(np.sum(u)) # Store metrics Ein_gt.append(np.mean(predictions != y_train)) epsilon_t.append(epsilon) # Step 3.4: Update combined hypothesis G_t G_t += alpha * predictions G_train_predictions = np.sign(G_t) Ein_Gt.append(np.mean(G_train_predictions != y_train)) G_test += alpha * (s * np.sign(X_test[:, feature] - theta)) G_test_predictions = np.sign(G_test) Eout_Gt.append(np.mean(G_test_predictions != y_test))
Editor is loading...
Leave a Comment