Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP ME COMPLETE THESE PYTHON PROGRAMMING ACTIVITIES Activity 5: Random Forest Classification - Model Training Implement Random Forest Classification using sklearn module in the

PLEASE HELP ME COMPLETE THESE PYTHON PROGRAMMING ACTIVITIES

Activity 5: Random Forest Classification - Model Training

Implement Random Forest Classification using sklearn module in the following way:

Deploy the model by importing the RandomForestClassifier class and create an object of this class.

Call the fit() function using the Random Forest Classifier object and print score using the score() function using the object created.

[ ]

 
 
# Import the required modules from the 'sklearn.ensemble' and 'sklearn.metrics' libraries # Train the Random Forest Classifier 

Q: What is the accuracy score?

A:

Q: Is it 100%?

A:

After this activity, a Random Forest Classification model object should be trained for multiclass classification.

Activity 6: Random Forest Classification - Model Prediction and Evaluation (Testing Set)

1. Predict the values for the testing set by calling the predict() function on the Random Forest Classifier object.

2. Print the unique labels predicted using Random Forest Regression on training features.

3. Print the distribution of the labels predicted in the predicted target series for the testing features.

[ ]

 
 
# Make predictions using Random Forest Classifier model object # Make predictions on the test dataset by using the 'predict()' function. # Check the count of records classified under each label # Print the unique labels in the predicted series for testing features # Print the distribution labels in the predicted series for testing features 

Q: Are all the label values predicted for the testing features data?

A:

Q: Which labels are predicted and not predicted by the Random Forest Classification model?

A:

4. Display the confusion matrix for the testing set:

[ ]

 
 
# Print the confusion matrix for the actual and predicted data of the test set (if required) 

5. Visualize the confusion matrix using the heatmap:

[ ]

 
 
# Create the heatmap for the confusion matrix # import the module # Create a series of all unique labels in actual target data # Create a Pandas DataFrame object for the confusion matrix created above labelled with the classes. # Create a heatmap for the confusion matrix. 

Note: Use fmt='d' as one of the parameters in the heatmap() to display the values in plain notation.

Q. Explain the heat map output in short based on the number of positive and negative outcomes for each class?

A

6. Display the classification report for the test set:

[ ]

 
 
# Print the classification report for the actual and predicted data of the testing set (if required) 

Q Which classes were identified correctly without any misclassification?

A

Q Which class has the lowest f1-score?

A

After this activity, labels should be predicted for the target columns using the test features set and the Random Forest Classifier model should be evaluated for the same.

Activity 7: Logistic Regression - Model Training

Implement Logistic Regression Classification using sklearn module in the following way:

Deploy the model by importing the LogisticRegression class and create an object of this class.

Call the fit() function on the Logistic Regression object and print the score using the score() function.

[ ]

 
 
# Build a logistic regression model using the 'sklearn' module. # 1. First, call the 'LogisticRegression' module and store it in 'lg_clg' variable. # 2. Call the 'fit()' function with 'X_train' and 'y_train' as inputs. # 3. Call the 'score()' function with 'X_train' and 'y_train' as inputs to check the accuracy score of the model. 

Q: What is the accuracy score?

A:

Q: Is it 100%?

A:

After this activity, a Logistic Regression model object should be trained for multiclass classification.

Activity 8: Logistic Regression - Model Prediction and Evaluation (Testing Set)

1. Predict the values for the test set by calling the predict() function on the Logistic Regression object.

2. Print the unique labels predicted using Logistic Regression on test features.

3. Print the distribution of the labels predicted in the predicted target series for the test features.

[ ]

 
 
# Predict the values of 'target' by the logistic regression model on the test set. # Predict the target for the test features data # Convert the predicted array into series # Print the unique labels in the predicted series for test features # Print the distribution labels in the predicted series for test features 

Q: Are all the labels predicted for the test features data?

A:

Q: What are labels predicted and not predicted using Logistic Regression model object?

A:

4. Display the confusion matrix for the test set:

[ ]

 
 
# Print the confusion matrix for the actual and predicted data of the test set (if required) 

5. Visualize the confusion matrix using the heatmap:

[ ]

 
 
# Create the heatmap for the confusion matrix generated by Logistic Regression testing predictions # Create a Pandas DataFrame object for the confusion matrix created above labelled with the classes. # Create a heatmap for the confusion matrix. 

6. Display the classification report for the test set:

[ ]

 
 
# Print the classification report for the actual and predicted data of the testing set (if required) 

Q Which classes were identified correctly without any misclassification?

A

Q Which class has the lowest f1-score?

A

After this activity, labels should be predicted for the target columns using the test features set and the Logistic Regression model should be evaluated for the same.

Write your interpretation of the results here.

Interpretation 1:

Interpretation 2:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

Students also viewed these Databases questions