Flash Sale: Flat 70% + Addl. 25% Off on all Courses | Use Coupon DS25 in Checkout | Offer Expires In

  Enroll Now

End to End ML Project - Fashion MNIST - Selecting the Model - Cross-Validation - Ensemble (Voting Classifier)

We will be performing k-fold cross-validation with 3 folds (cv=3) on the Ensemble (VotingClassifier) model, and calculating the mean accuracy, precision, recall and F1 score values for the same.

INSTRUCTIONS

Please follow the below steps:

Please create an instance of VotingClassifier called voting_clf, which is an Ensemble of Softmax Regression and RandomForestClassifier.

Firstly create an instance of Logistic Regression called log_clf_ens by passing it the parameters - multi_class="multinomial", solver="lbfgs", C=10 and random_state=42

log_clf_ens = LogisticRegression(<<your code comes here>>)

Now, create an instance of RandomForestClassifier called rnd_clf_ens by passing it the parameters - n_estimators=20, max_depth=10 and random_state=42

rnd_clf_ens = RandomForestClassifier(<<your code comes here>>)

Let us create an instance of VotingClassifier by passing to it the above created estimators - log_clf_ens and rnd_clf_ens - and also voting='soft'

voting_clf = VotingClassifier(
    estimators=[('lr', <<your code comes here>>), ('rf', <<your code comes here>>)],
    voting='soft')

Please call cross_val_score() function by passing following parameters to it - the model (voting_clf), the scaled training dataset (X_train_scaled), y_train, cv=3 and scoring="accuracy" - and save the returned value in a variable called voting_cv_scores.

Call display_scores() function, by passing to it the voting_cv_scores variable, to calculate and display(print) the 'accuracy' score, the mean of the 'accuracy' score and the 'standard deviation' of the 'accuracy' score.

voting_cv_scores = cross_val_score(<<your code comes here>>) 
display_scores(voting_cv_scores)

Call mean() method on voting_cv_scores object to get the mean accuracy score and store this mean accuracy score in a variable voting_cv_accuracy.

voting_cv_accuracy = voting_cv_scores.<<your code comes here>>

Please call cross_val_predict() function by passing following parameters to it - the model (voting_clf), the scaled training dataset (X_train_scaled), y_train, cv=3 - and save the returned value in a variable called y_train_pred.

y_train_pred = cross_val_predict(<<your code comes here>>)

Compute the confusion matrix by using confusion_matrix() function

confusion_matrix(y_train, <<your code comes here>>)

Calculate the precision score by the using the precision_score() function

voting_cv_precision = precision_score(y_train, <<your code comes here>>, average='weighted')

Calculate the recall score by the using the recall_score() function

voting_cv_recall = recall_score(y_train, <<your code comes here>>, average='weighted')

Calculate the F1 score by the using the f1_score() function

voting_cv_f1_score = f1_score(y_train, <<your code comes here>>, average='weighted')

Print the above calculated values of voting_cv_accuracy, voting_cv_precision, voting_cv_recall , voting_cv_f1_score


No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...