Answered step by step
Verified Expert Solution
Link Copied!

Question

00
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

Q2. Logistic Regression: Code [25]
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 60% of the data selected randomly for training, 20% selected randomly for testing and
the remaining 20% 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 ?3, fit the cleaned train data. This will create the bag-of-words
model for the train data. Transform test and validation sets using same CountVectorizer.
To implement the logistic regression using following equations,
zi=W*xi
hat(y)i=(zi)
we need the weight vector W. Create an array of dimension equal to those of each xi
from the CountVectorizer.
Apply above equations over whole training dataset and calculate hat(y) and cross-entropy
loss LCE which can be calculated as
LCE=-yloghat(y)+(1-y)log(1-hat(y))
Now, update the weights as follows:
Wt+1=Wt-(hat(y)i-yi)*xi
Here, (hat(y)i-yi)*xi is the gradient of sigmoid function and =0.01 is the learning rate.
Repeat step 4 and step 5 for 500 iterations or epochs. For each iteration, calculate the
cross-entropy loss on validation set.
Calculate the accuracy and macro-average precision, recall, and F1 score and provide
the confusion matrix on the test set.
Experiment with varying values of in(0.0001,0.001,0.01,0.1). Report your observations
with respect to the performance of the model. You can vary the number of iterations to
enhance the performance if necessary.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Which are non projected Teaching aids in advance learning system?

Answered: 1 week ago