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
The pyramid of khagra,in Egypt,is 488 feet tall. The Eiffel Tower,in France,is 1,063 feet tall. How much taller is the Eiffel To
steposvetlana [31]

Answer:

The Eiffel Tower in France is 575 feet taller than pyramid of khagra.          

Step-by-step explanation:

We are given the following in the question:

Height of pyramid of khagra = 488 feet

Height of Eiffel Tower in France = 1,063 feet

Difference in height =

= Height of Eiffel Tower in France - Height of pyramid of khagra

=1063 - 488\\= 575\text{ feet}

Thus, the Eiffel Tower in France is 575 feet taller than pyramid of khagra.

7 0
3 years ago
Find the distance (8,-7) (-4,-2)
Vinil7 [7]

Distance = 13 units

Point A: (8, -7)

Point B: (-4, -2)

\sqrt{(8 + 4)^{2} + (-7 + 2)^{2} }

\sqrt{(12)^{2} + (-5)^{2} }

\sqrt{144 + 25 }

\sqrt{169}

13

7 0
3 years ago
Read 2 more answers
Which expression equals 6x − 5y + 2 − 8x + 3( y + 5)? A) 3x − 2y + 17 B) −3x + 2y + 17 C) −2x − 2y + 17 D) −2x − 2y − 17
inysia [295]

Answer:

<u>C) −2x − 2y + 17</u>

Step-by-step explanation (PEMDAS):

First, we do <u>3 (y + 5)</u> because of the parenthesis:

6x − 5y + 2 − 8x + 3y + 15

Since there are no exponents, multiplication ,or division, we will add and subtract. But we have to make sure we <u>combine like terms</u>. X with X's, Y with Y's and constants with constants. And ALWAYS go from left to right

6x − 5y + 2 − 8x + 3y + 15

<u>−2x</u> − 5y + 2 + 3y + 15

−2x <u>− 2y</u> + 2 + 15

<em>−2x − 2y</em><em> </em><em>+ </em><em><u>17</u></em><em>.</em>

8 0
3 years ago
IF YOU HELP ME WITH THIS I WILL HELP YOU WITH SOMETHING IF YOU NEED HELP!! State if each triangle is a right triangle. The trian
juin [17]

Answer:

6 - yup        7 - nope

Step-by-step explanation:

If the triangle satisfies the pythagoreon theorem, then it is a right triangle

so 6 is a yeah

then for 7, the hypotunese always is greater than the legs in a right triangle, so 7 is no

4 0
3 years ago
Identify the location of the point (-3, -2).<br><br> A. P<br> B. Q<br> C. R<br> D. S
docker41 [41]

Answer:

You haven't given a picture of the graph dear.

The point (-3,-2) lies in the third quadrant.

8 0
2 years ago
Other questions:
  • WILL GIVE BRIANIEST TO CORRECT ONLY
    8·1 answer
  • H/6-1=-3. What is h?
    7·1 answer
  • The graph of 15x + 7y = 15 is shown on the grid. Which ordered pair is in the solution set of 15x + 7y ≥ 15?
    14·1 answer
  • To get to the next term in this sequence, multiply the last term by 2.5. What is the value of the next term?
    8·1 answer
  • X2 + 5x +4=0<br> How do we do this
    6·2 answers
  • Which graph shows the solution set for -5/2x -3&lt;2 ​
    7·2 answers
  • 52 &gt; 43 + w
    9·1 answer
  • Using divisibility test,circle the numbers that are divisible by 11 the number is 16
    6·1 answer
  • 81 + 7x² +8yt-sx<br> if x = 2 what is the answer
    5·1 answer
  • Find an equivalent ratio in simplest terms: 12 : 40​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!