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
86.40-12.59 plz answer
Evgen [1.6K]
The answer is 73.81 :))
8 0
2 years ago
Read 2 more answers
What are the coordinates of point F?
sashaice [31]
D, its (x,y) and (8.2,5.7) are the only ones that match up
5 0
3 years ago
A bag contains 42 red, 45 green, 20 yellow, and 32 purple candies, you pick one candy at random, find the probability that it is
Gnesinka [82]

Answer:

P (green/yellow) = 65/139

Step-by-step explanation:

42 + 45 + 20 + 32 = 139 possibilities

45 + 20 = 65 desired outcomes

65/139


Hope this helps!


3 0
3 years ago
(x+7)(x-9)<br><br> Multiply Ponomials <br><br> show work please
Murrr4er [49]

Answer:

x(x-9)+7(x-9)

x²-9x+7x-63

x²-2x-63

7 0
2 years ago
What is the value of g(2)? Please show work
4vir4ik [10]

By the inequality for x over on the right side if x is equal to or greater than 2 you use the bottom equation.

G(2) means x is 2.

Using the bottom equation replace the x’s with 2 and solve.

X^3 -9x^2 +27x-25

2^3 -9(2)^2+27(2)-25

Simplify:

8 -36 + 54-25 =1

The answer is A. 1

8 0
2 years ago
Other questions:
  • 6=a/4+2 solve for a
    14·2 answers
  • A study by Consumer Reports showed that 64% of supermarket shoppers believe supermarket brands to be as good as national name br
    10·1 answer
  • Help what is x<br> When x^5 is 225
    7·2 answers
  • Does anybody know the answer to this
    6·2 answers
  • Sonny works as a furniture salesman and earns a base salary of $350 per week plus 6% commission on sales. If Sonny sold $3,750 i
    5·1 answer
  • What is the median of the data represented by the box plot?
    8·1 answer
  • Use the Distributie<br> Property to express<br> 27 + 60
    9·2 answers
  • I need all the points marked
    6·1 answer
  • Each day Diego's mother drives to her office in Baltimore. The driving distance from home to Baltimore, Maryland is 7 miles. On
    14·1 answer
  • Find the length of x. Assume the triangles are similar.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!