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]
3 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]3 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
Four employees of papa Tony's Pizza are cleaning up at the end of a busy night. There is a list of 43 clean up tasks that need t
Eduardwww [97]
Hello There!

You divide 43 by 4:
43/4 = 10.75
It isn't a whole number.
Therefore, each employee would do approximately 11. 
However, the exact amount is 10.75

Hope This Helps You!
Good Luck :) 

- Hannah ❤ 
4 0
3 years ago
Read 2 more answers
a cylindrical vase has a diameter of 6 inches at the bottom of the vase there are 9 marbles each of diameter 3 inches the vase i
KiRa [710]

Answer:

<h2>The volume of water in the vase is 339.33 in^3</h2>

Step-by-step explanation:

To calculate the volume of water in the vase we need the following parameters

1. the diameter/radius of the vase

2. the height /level of water in the vase

Given data

diameter d= 6 in

radius = d/2= 6/2 = 3 in

height of water h= 12 in

we know that the expression for the volume of a cylinder is given as

volume=  \pi r^2h

Inserting our data we have

volume= 3.142*3^2*12\\\volume= 3.142*9*12\\\volume= 339.33 in^3

3 0
3 years ago
How many times 3 go into 97
vlabodo [156]

32

This is the answer...

7 0
3 years ago
Read 2 more answers
Why could I write 10 + 10 + 8 + 8 as (10*2) + (8*2)?
Alisiya [41]

Answer:

yes

Step-by-step explanation:

6 0
3 years ago
Find the area and circumference of each circle.
ale4655 [162]

Area = πr^2

Circumference = 2πr

Blue:

Area = 5^2 = 25π

Circumference = 2 * 5 * π = 10π

Pink:

Area = 6^2 = 36π

Circumference = 2 *6*π = 12π

White:

r = 3

Area = 3^2 = 9π

Circumference = 2 *3 = 6π

Red:

Area = 7^2 = 49π

Circumference = 2 *7 = 14π

4 0
4 years ago
Other questions:
  • The answers would be great
    13·1 answer
  • Determine the value of c that will result in a perfect square trinomial<br> w^2 + 6w + c = 130 + c
    14·1 answer
  • What is equivalent to 3(5+4)
    15·1 answer
  • 2x + 2 = 5x – 10<br> answer plssssss
    10·2 answers
  • The sum of two consecutive integers is 119​
    8·1 answer
  • How to round the number 3.987 to the nearest tenths
    7·1 answer
  • If all sides of a cube are multiplied by six by what factor does the volume increase
    14·1 answer
  • Please help ASAP. I’m confused
    10·1 answer
  • Find the common ratio and explicit formula for 2, 3, 4.5, 6.75,
    5·2 answers
  • Between which two consecutive whole numbers does \sqrt{51} lie?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!