Question: # CG Q0 # Read in the data as tlmrk. tlmrk

# 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?

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

(sum(tlmrk$subscribe) / 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(glm(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.

# 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.

yhat3 <- as.numeric(fit$fitted > rule3)

I need help with #2, 6a, 6b, 7, 8, 9 please and thank you in advance!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!