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
Which of the following sets of numbers could be the lengths of the sides of a
Rudik [331]
The answer would be OC, most triangles, like right triangles have equivalent sides. 12, 12, 12in
7 0
2 years ago
Find the gain or loss per cent, if <br>C.P. = 200 and S.P. = 224​
motikmotik
Ah sana masgot nyu toh natatae na ako saglit lang 3583 is answer kaso nag huhugas pa ako ng plato saglit
7 0
3 years ago
emily has a bowl of M&amp;M's for every 25 M&amp;M's there are blue 5 M&amp;M's. what percent of her M&amp;M's are blue
KonstantinChe [14]

Answer:

twenty percent.

Step-by-step explanation:

25/5=5

100/5=20

8 0
2 years ago
Samples of a cast aluminum part are classified on the basis of surface finish (in microinches) and edge finish. The results of 1
liubo4ka [24]

Answer:

a) P (A)= 88/102= 0.8627

(b) P (B)=  89/102= 0.8725

c) P (A`) =  14/102 = 0.1372

(d) P (A∩B) = 84/102 =0.8235

(e) P(AUB)= 93/102 = 0.9117

(f)P (A`UB) = 98/102= 0.96078

Step-by-step explanation:

                                                                   edge                  

                                                  finish excellent       good           Total

<u>(A )surface finish excellent            84                      4                  88</u>

good                                    ( B) ⇵    5                       9                  14

Total                                               89                      13                102

a) Upper P left-parenthesis Upper A right-parenthesis equals

P (A)= 88/102= 0.8627

All the elements of set A = 84+4= 88

(b) Upper P left-parenthesis Upper B right-parenthesis equals

P (B)=  89/102= 0.8725

All the elements of set B = 84+5= 89

c) Upper P left-parenthesis Upper A prime right-parenthesis equal

P (A`) =  14/102 = 0.1372

All the elements of Universal set U which are not elements of set A = 102- 88= 14

(d) Upper P left-parenthesis Upper A intersection Upper B right-parenthesis equals

P (A∩B) = 84/102 =0.8235

Only those elements of set A and set B which are common

(e) Upper P left-parenthesis Upper A union Upper B right-parenthesis equals

P(AUB)= 93/102 = 0.9117

Totalling elements of set A and B= 88+5= 93

(f) Upper P left-parenthesis Upper A prime union Upper B right-parenthesis equals

P (A`UB) = 98/102= 0.96078

All the elements of Universal set U which are not elements of set A and the elements of Set B = 5+9+ 84= 98

6 0
3 years ago
By the literal surface of the triangular prism 90 in2 110 in2 120 in2 130 in2
Sergio039 [100]

Answer:

3

Step-by-step explanation:

Your answer is 3

8 0
2 years ago
Read 2 more answers
Other questions:
  • What is the first step to solving this equation? -5c + 6 = -4
    9·2 answers
  • If f(x) = 4x - 20, what is f(4)?<br> O A. -12<br> O B. 4<br> O C. 16<br> O D.-4
    8·2 answers
  • Simplify the expression
    5·2 answers
  • Two circles have radii 16cm and 23cm. what is the difference between their circumference ?​
    9·2 answers
  • Please help! (Number 2)
    14·1 answer
  • An 8-foot rope is tied from the top of a pole to a stake in the ground,as shown in the diagram below.
    6·1 answer
  • The graph shows the number of tacos ordered and the cost.<br> What is the unit rate?
    14·1 answer
  • Please help me? I am confused.​
    11·1 answer
  • What is the decimal equivalent of 7/12?
    7·2 answers
  • PLEASE HELP!! Find the equation of the line that is perpendicular to y= -2/3x and contains the point (4,-8).
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!