Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to understand naive Bayesian Classification in R language Classification algorithm

Shulou Source: shulou.com Published: 2022-06-01 00:24:34 09月27日 Update

This article shows you how to understand the naive Bayesian classification in the R language classification algorithm, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Analysis of the principle of naive Bayesian Classification

According to the known prior probability P (A | B), a posteriori probability P (B | A) is obtained by using Bayesian formula P (B | A) = P (A | B) P (B) / P (A), that is, the probability that the sample belongs to a certain class, and then the class with the maximum a posteriori probability is selected as the class to which the sample belongs.

That is to say, for the given sample to be classified, if we find out the probability of each category under the condition of the occurrence of the sample, which one is the largest, the sample is considered to belong to which category.

Its advantage is that it is not afraid of noise and independent variables, and its disadvantage is that it assumes that each feature attribute is irrelevant, which is often not the case in reality.

two。 Application in R language

Naive Bayesian classification mainly uses the NaiveBayes (formula,data,...,subset,na,action=na.pass) function in the klaR package.

3. Discriminant analysis with iris dataset as an example

1) apply the model and observe the results

Library (klaR) fit_Bayes1=NaiveBayes (Species~.,data_train) fit_ Bayes 1 [1: length (fit_Bayes1)]

2) make a density curve

Plot (fit_Bayes1)

3) Predictive analysis and evaluation of the model

Pre_Bayes1=predict (fit_Bayes1,data_test) pre_Bayes1

Table (data_test$Species,pre_Bayes1 $class) error_Bayes1=sum (as.numeric (as.numeric (pre_Bayes1 $class)! = as.numeric (data_test$Species) / nrow (data_test); error_Bayes1

The above content is how to understand the naive Bayesian classification in the R language classification algorithm. have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Classification Baye sample probability simplicity language algorithm maximum content skill model knowledge category derivation analysis application conciseness conciseness that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno Shulou Technology Redmi Xiaomi