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
Use the euclidean algorithm to find
kvasek [131]
A)
18=1\cdot12+6
12=2\cdot6+0
\implies\mathrm{gcd}(12,18)=6

b)
201=1\cdot111+90
111=1\cdot90+21
90=4\cdot21+6
21=3\cdot6+3
6=2\cdot3+0
\implies\mathrm{gcd}(111,201)=3

c)
1331=1\cdot1001+330
1001=3\cdot330+11
330=30\cdot11+0
\implies\mathrm{gcd}(1001,1331)=11

d)
54321=4\cdot12345+4941
12345=2\cdot4941+2463
4941=2\cdot2463+15
2463=164\cdot15+3
15=5\cdot3+0
\implies\mathrm{gcd}(12345,54321)=3

e)
5040=5\cdot1000+40
1000=25\cdot40+0
\implies\mathrm{gcd}(1000,5040)=40

f)
9888=1\cdot6060+3828
6060=1\cdot3828+2232
3828=1\cdot2232+1596
2232=1\cdot1596+636
1596=2\cdot636+324
636=1\cdot324+312
324=1\cdot312+12
312=26\cdot12+0
\implies\mathrm{gcd}(9888,6060)=12
8 0
3 years ago
Determine the area of this figure. Round your answer to the nearest tenth place.
denis-greek [22]
36 feet okay it is 36 feet of the area
5 0
2 years ago
The basketball players at
kupik [55]
Give us more information
8 0
3 years ago
Read 2 more answers
Will pick brainlyest help me plz 15 pts
leonid [27]
1.50c + 2.50a = 1100
c + a = 500

multiply the second equation by -1.50
                    
                      1.50c + 2.50a = 1100
-1.50c - 1.50a = -7.50


8 0
3 years ago
What is .9898 as a fraction
AysviL [449]
98 98/100 because you move the decimal point over 2 times
3 0
2 years ago
Other questions:
  • Use the distributive property to remove the parentheses. Simplify your answer as much as possible.
    13·2 answers
  • Which shows the expressions in the order they would appear on a number line from least to greatest?
    10·2 answers
  • A plane takes off at an angle of 15 and travels in a straight line for 3000 meters what's the height
    15·1 answer
  • Hellllp pleaseeeee !
    10·2 answers
  • How to find lattice parameter from fourier transform cryoem?
    12·1 answer
  • What is the common difference for this aritmetic sequence -5,-1,3,7,11
    12·2 answers
  • Complete this quiz to finish the assignment for 3A - Geometry Pap due on Mar 23, 2021
    8·1 answer
  • Leap years are years in which February has 29 days instead of 28. The device of leap year was invented to keep the calendar in s
    5·1 answer
  • Complete the equation of the line through (-6,5) and<br> (-3, -3).<br> Use exact numbers.
    15·1 answer
  • PLEASE HELP ASAP!! WILL GIVE BRAINLIEST <br> what is the exact value of tanC
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!