1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mote1985 [20]
2 years ago
7

Randomly split the messages into a training set D1 (80% of messages) and a testing set D2 (20% of messages). Calculate the testi

ng accuracy, confusion matrix, precision, recall, and F-score of the Na¨ıve Bayes classifier in determining whether a message is spam or ham. Submit your source code. Note: Let’s assume that spam is the positive class
Mathematics
1 answer:
Blizzard [7]2 years ago
3 0

Answer:

In the step-by-step

Step-by-step explanation:

This is the code i created using the R software and the packages "caret" and "e0171".

The script was supposed to work in all general cases.

library(caret)

library(e1071)

# Categorical vector

spam <- c("spam","not_spam")

spam_vec <- sample(spam,60, replace = T)

# Supposing two independent variables so that the kappa will be close to 0.

x1 <- rnorm(60)

x2 <- rnorm(60)

# Creating the dataset

data1 <- cbind(spam_vec,x1,x2)

data1 <- as.data.frame(data1)

names(data1) <- make.names(c("spamvec","x","y"))

# Creating the partition

index <- createDataPartition(data1$spamvec,

                            p=0.8, list=FALSE)

training_data <- data1[index,]

testing_data <- data1[-index,]

fitControl <- trainControl(method = "cv",

                         number = 5,

                         savePred = TRUE,

                         classProb = TRUE)

tune.grid <- expand.grid(C = seq(0, 10, .1))

# Scaling the predictors

preProcess_cs <- preProcess(training_data[, -1],

                                 method = c("center", "scale"))

spam_training_cs      <- predict(preProcess_cs, training_data)

spam_testing_cs       <- predict(preProcess_cs, testing_data)

# Training a Naive Bayes to predict binary outcome

Naive_Bayes_Model=naiveBayes(spamvec ~.,

                            data=spam_training_cs,

                            tuneGrid = tune.grid,

                            trControl = fitControl)

# Confusion matrix

prediction <- predict(Naive_Bayes_Model, spam_testing_cs)

confusionMatrix(prediction, spam_testing_cs$spamvec, positive = "spam")

confM <- confusionMatrix(prediction, spam_testing_cs$spamvec, positive = "spam")

accuracy <- confM$overall[1]

accuracy

You might be interested in
6.
Lady_Fox [76]

Answer:

Choice A

Step-by-step explanation:

Use the F. O. L. D method while solving

4 0
3 years ago
The sum of two consecutive odd integers is greater than 36 (solve with an inequality and show work please)
mixas84 [53]
O+o+2>36
2o>34
o>17
o1>17
o2>19
o is equal to odd number
4 0
2 years ago
A motorcycle shop maintains an inventory of four times as many new bikes. If there are 80 new bikes, how many used bikes are now
Ghella [55]
Answer: There are 20 used bikes



Explanation: If there are 4 times the used bikes then you would have to do 80 divided by 4 and there’s the answer
7 0
3 years ago
Read 2 more answers
How many times does 27 go into 890
Luba_88 [7]
32.96, to get this answer, you have the divide 890 by 27 
5 0
3 years ago
Let g be the function given by g(x)=x^2*e^(kx) , where k is a constant. For what value of k does g have a critical point at x=2/
ArbitrLikvidat [17]
G `( x ) =2x * e^{kx}  + k x^{2} *e^{kx} = \\  = xe^{kx}(2 + kx )
2 + k x = 0
k x = -2
k = -2: x = - 2 : 2/3 = - 2 * 3/2
k = - 3
Answer: for k= - 3, the function g ( x ) have a critical point at x = 2/3. 
8 0
3 years ago
Other questions:
  • Which statements are true? check all that apply
    10·2 answers
  • I need help it would be great if you answered it
    8·2 answers
  • Jane wants to estimate the proportion of students on her campus who eat cauliflower. after surveying 35 ​students, she finds 4 w
    14·1 answer
  • Identify the underlined place in 83.5851. Then round to the nearest thousandth
    5·2 answers
  • Why is easier to subtract when numbers are written above and bellow each other?
    6·2 answers
  • Simplify using the vertical method. (3k + 5)(2k^2 – 5k – 3)
    11·2 answers
  • The inequality 7h+45≥143 represents the minimum number of hours, h, it will take a chef to make at least 143 croissants. The tab
    10·1 answer
  • 1. Write the equation of the circle given the following information. *
    11·1 answer
  • Help! Its too hard! I cant figure it our
    8·1 answer
  • Mr. Peterson graded 126 tests in 3 hours. How many tests can he grade in 5 hours?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!