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
What is the average speed?
pashok25 [27]
Average speed of what?
5 0
3 years ago
Read 2 more answers
Round 1.625 to the nearest hundredth
Fantom [35]

Answer:

1.600

Step-by-step explanation:

because 25 is to low to round to a 100th number so u go back to 600.

4 0
3 years ago
Read 2 more answers
What is the effect on the graph of the function f(x) = sqrt 10x when f(x) is replaced with f(x − 5)?
Olin [163]

Answer:

The graph experiences a translation of 5 units to the right.



3 0
3 years ago
Graph y = -2 and x= 3 individually state the slope and x and y intercept form for each
attashe74 [19]

y = -2 and x= 3

Graph is attached below. Black line is the graph of y=-2

Blue line is the graph of x=3

Whenever we get equation like x = something, in that case slope is always undefined

Whenever we get equation like y = something, in that case slope is always 0

y = -2 and x= 3

For x=3, the slope is undefined.

The graph of x=3 is a vertical line at 3 on x. The x intercept is 3 and there is no y intercept.

For y=-2, the slope is 0

The graph of y=-2 is a horizontal line at -2 on y. The y intercept is -2 and there is no x intercept.


4 0
3 years ago
A bacteria culture contains 1500 bacteria initially and doubles every hour. (a) Find a function N that models the number of bact
Tpy6a [65]

Answer: a) N(t)=1500(2)^t

b) 25165824000

Step-by-step explanation:

The exponential equation for growth is given by :-

y= ab^t , where a= initial value , b =multiplicative growth factor and t = time.

Given : A bacteria culture contains 1500 bacteria initially and doubles every hour.

i.e. a = 1500 and b= 2

Then, the function N that models the number of bacteria after t hours will be :

N(t)=1500(2)^t

To find , the number of bacteria after 24 hours , we put t= 24 in above equation , we get

N(24)=1500(2)^{24}\\\\=1500(16777216)=25165824000

Hence, the number of bacteria after 24 hours is 25165824000.

7 0
3 years ago
Other questions:
  • There are 150 kangaroos at a wildlife park there are 66 female what percentage is female
    12·1 answer
  • This number represents the equal number of parts that equal a whole in a fraction
    11·2 answers
  • . Karen is building a model of the Lincoln Memorial for her History class. She found online that the building measures 204 feet
    13·2 answers
  • What is the graph of the function?<br> F(x) = 1/2x^2
    8·1 answer
  • What is the slope of the line that.passes through (76,5) and (82,83)​
    9·1 answer
  • 10x - 22 = 29 - 7x. What is the value of x
    7·1 answer
  • Pls help me solve please show how you got the answer pls help
    5·1 answer
  • ) Would you rather receive $1,500 a year for 12 years, or $1,200 a year for 20 years if the interest rate is 7%?
    11·1 answer
  • What is the scale factor of the dilation?
    15·1 answer
  • Help please I don’t understand it What is the sum of these questions?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!