Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q 2 . Logistic Regression: Code [ 2 5 ] In this task, you will learn to build a Logistic Regression Classifier for the same
Q Logistic Regression: Code
In this task, you will learn to build a Logistic Regression Classifier for the same "Financial
Phrasebank" dataset. Bag of Words model will be used for this task.
Use of the data selected randomly for training, selected randomly for testing and
the remaining for validation set. Use classes 'positive' and 'negative' only. Perform
the same cleaning tasks on the text data and build a vocabulary of the words.
Using CountVectorizer fit the cleaned train data. This will create the bagofwords
model for the train data. Transform test and validation sets using same CountVectorizer.
To implement the logistic regression using following equations,
hat
we need the weight vector W Create an array of dimension equal to those of each
from the CountVectorizer.
Apply above equations over whole training dataset and calculate hat and crossentropy
loss which can be calculated as
hat
Now, update the weights as follows:
Here, is the gradient of sigmoid function and is the learning rate.
Repeat step and step for iterations or epochs. For each iteration, calculate the
crossentropy loss on validation set.
Calculate the accuracy and macroaverage precision, recall, and F score and provide
the confusion matrix on the test set.
Experiment with varying values of Report your observations
with respect to the performance of the model. You can vary the number of iterations to
enhance the performance if necessary.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started