Error " Variable ‘voting_clf’ not defined" on below code
from sklearn.ensemble import VotingClassifier
log_clf_ens = LogisticRegression(multi_class=“multinomial”, solver=“lbfgs”, C=10, random_state=42)
rnd_clf_ens = RandomForestClassifier(n_estimators=100, max_depth=50, random_state=42)
voting_clf = VotingClassifier(
estimators=[(‘lr’, log_clf_ens), (‘rf’, rnd_clf_ens)],
voting=‘soft’)
voting_clf.fit(X_train_scaled, y_train)
Let us predict some instance from the data set using the above trained model
y_train_predict = voting_clf.predict(X_train[0].reshape(1, -1))
y_train[0]
Let us see the predicted class
y_train_predict[0]
showImage(X_train[0])
Let us predict all instances of training dataset X_train_scaled using the above trained model
y_train_predict = voting_clf.predict(X_train_scaled)
voting_accuracy = accuracy_score(y_train, y_train_predict)
voting_precision = precision_score(y_train, y_train_predict, average=‘weighted’)
voting_recall = recall_score(y_train, y_train_predict, average=‘weighted’)
voting_f1_score = f1_score(y_train, y_train_predict, average=‘weighted’)
print("Ensemble Accuracy: ", voting_accuracy)
print("Ensemble Precision: ", voting_precision)
print("Ensemble Recall: ", voting_recall)
print("Ensemble F1 Score: ", voting_f1_score)