Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help. I have everything right up to question 6 CG Q0 # Read in the data as tlmrk. tlmrk

Please help. I have everything right up to question 6

CG Q0 # Read in the data as tlmrk.

tlmrk <- read.csv("telemarketing.csv", strings = T)

# CG Q1 # Use the nrow() function to find the nummber of customer records.

nrow(tlmrk)

# CG Q2 # How many customers in this dataset subscribed to a term deposit product?

sum(tlmrk$subscribe==1)

# CG Q3 # Find the percent of customers that subscribed to a term deposit product.

sum(tlmrk$subscribe==1) / nrow(tlmrk)*100

# CG Q4a # Fit a logistic regression model for subscribe modeled by all other possible

########## variables in the data set plus the variable durmin squared using the code below.

fit <- glm(subscribe ~ . + I(durmin^2), data=tlmrk, family="binomial")

# CG Q4b # Use length() combined with the coef() function to find how many

########## coefficients were estimated by glm().

length(coef(fit))

# CG Q5 # Find the R-squared for the fitted regression by referring to the

######### deviances from summary.glm (use the code from youe lecture examples).

1 - (fit$deviance / fit$null.deviance)

# CG Q6a # Customer 27 in our dataset did not end up subscribing to the term deposit.

########## Let's use our fitted model to see what it would have predicted for this customer.

########## First, create an object called "nd" that that you will pass to the predict()

########## function in the newdata argument.

# CG Q6b # Use your fitted logistic regression and your "newdata" in the predict()

########## function to make a prediction of the probability the customer would subscribe.

predict(fit, newdata=nd, type="response")

# CG Q7 # Use the following code to create a confusion matrix and calculate the PPV.

rule <- 1/5 # classification rule

yhat <- as.numeric(fit$fitted>rule) # classify subscription status based on your rule

table(yhat, actualSubscriptionStatus=tlmrk$subscribe) # confusion matrix

# Now, use the confusion matrix to calculate the sensitivity (recall).

# CG Q8 # Now, for a classification rule of 1/12, find the PPV (precision).

######### You should submit 4 separate lines of code.

# CG Q9 # Calculate the specificity for a rule of 1/3 using 4 lines of code again.

######### Name the rule object rule3 and your predicted subscription status yhat3.

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

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

Recommended Textbook for

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions

Question

To find integral of sin(logx) .

Answered: 1 week ago

Question

What is Centrifugation?

Answered: 1 week ago