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
An average rate of change of 2 and has a value of 0 when x=-1
r-ruslan [8.4K]
I don't know I'm sorry
7 0
3 years ago
Plz show your work. Thx!! <br> 9m=6
grandymaker [24]
So first you would divide the 9 on both sides then 6 divided by 9 would be .6 repeating so m=.6 repeating.

5 0
3 years ago
Rose picked 18 tulips and 20 lilies.She divided the flowers into groups so that the same number of tulips and lilies were in eac
RSB [31]

Anwser: 18=9 groups  and 20= 10 groups

5 0
3 years ago
Read 2 more answers
A system of equations consists of a line s of the equation y = x – 5 and a line t that passes through the points (0, 2) and (8,
GenaCL600 [577]

Answer:

\text{The slope of the line t:}\ m=-\dfrac{3}{4}\\\\\text{The y-intercept of the line t:}\ b=2\\\\\text{The equation of a line t in the slope-intercept form:}\ y=-\dfrac{3}{4}x+2

Step-by-step explanation:

The slope-intercept form of an equation of a line:

y=mx+b

m - slope

b - y-intercept → (0, b)

The formula of a slope:

m=\dfrac{y_2-y_1}{x_2-x_1}

We have two points (8, -4) and (0, 2) → b = 2.

Calculate the slope:

m=\dfrac{2-(-4)}{0-8}=\dfrac{6}{-8}=-\dfrac{3}{4}

Therefore the equation of a line t in the slope-intercept form is:

y=-\dfrac{3}{4}x+2

5 0
3 years ago
Read 2 more answers
How do you solve the equation 2/7m-1/7=3/14
photoshop1234 [79]
Add 1/7 to both sides to get 2/7m=3/14+1/7 find common denominater (14) so multipy 1/7 by 2 to get 2/14 than add that to 3/14 to get 5/14 than take 2/7 and 5/14 turn into a decimals than divide the 2/7 on both sides to get m=?
8 0
3 years ago
Other questions:
  • when three different numbers are chosen from the set {-3,-2,-1,4,5) and multiplies the greatest possible product is
    11·1 answer
  • Write the equation of a line with a slope of 5 that passes through the point (3,1)
    10·1 answer
  • What is 4 7/9 +2 5/6
    10·1 answer
  • A tree that is 100 feet tall casts a shadow that is 150 feet long. Determine the angle at which the rays of the sun hit the grou
    10·2 answers
  • PLEASE HELP !!! 15 POINTS !! PLUS BRAINLIEST !!
    15·2 answers
  • The table represents a linear equation.
    7·2 answers
  • PLEASE HELP!!!!<br> solve for x.
    9·1 answer
  • According to Masterfoods, the company that manufactures M&amp;M’s, 12% of peanut M&amp;M’s are brown, 15% are yellow, 12% are re
    13·1 answer
  • Solve each equation. Check your solution.<br> 3(n - 7) = -30
    14·2 answers
  • Help me please and thank you .
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!