# Statistics For Data Science with Python — Classification (2/10)

*Let’s Show Classification* Algorithms

### 1.Naive Bayes

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174177723/s3h_bRSoq.jpeg)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174179154/FQdSIIhen.png)

*   Simple and efficient tools for predictive data analysis
*   Accessible to everybody, and reusable in various contexts

### Built on NumPy, SciPy, and matplotlib

### Notebook Python

#### a) Loading Data Set

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174180459/UGD4BvLp0.png)

#### b) Data Clean

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174182028/rQeDEmZIX.png)

#### c) Train & Test Base

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174183643/0sos9bjfF.png)

#### d) Gaussian Naive Bayes Classification

`[**GaussianNB**](https://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.GaussianNB.html#sklearn.naive_bayes.GaussianNB "sklearn.naive_bayes.GaussianNB")` implements the Gaussian Naive Bayes algorithm for classification. The likelihood of the features is assumed to be Gaussian:

P(xi∣y)=12πσy2exp⁡(−(xi−μy)22σy2)

The parameters σy and μy are estimated using maximum likelihood.

\>>>

**\>>> from** **sklearn.datasets** **import** load\_iris  
**\>>> from** **sklearn.model\_selection** **import** train\_test\_split  
**\>>> from** **sklearn.naive\_bayes** **import** GaussianNB  
**\>>>** X, y = load\_iris(return\_X\_y=**True**)  
**\>>>** X\_train, X\_test, y\_train, y\_test = train\_test\_split(X, y, test\_size=0.5, random\_state=0)  
**\>>>** gnb = GaussianNB()  
**\>>>** y\_pred = gnb.fit(X\_train, y\_train).predict(X\_test)  
**\>>>** print("Number of mislabeled points out of a total *%d* points : *%d*"  
**... **      % (X\_test.shape\[0\], (y\_test != y\_pred).sum()))  
Number of mislabeled points out of a total 75 points : 4

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174185004/Rrd9J1DX0.jpeg)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174186432/0i0GqIm29.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174188057/o44CPXhje.png)

### 2\. Undersampling x Oversampling

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174189490/X4qE7gVRQ.png)

### 3\. Undersampling with Tomek Links

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174190835/6ekLGYtXe.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174192203/0tntsP_hx.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174193560/1qQ2GQZ9K.png)

### 4\. Oversampling with Smote

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174194970/o_0f1Bprn.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174196366/K1IeyBcveK.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174197984/3mEtMS1cOc.png)

### Notebook Python with Code

*   Naive Bayes
*   Undersampling
*   Oversampling

### A example with Rando Forest

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174199312/0ZO93PMIhd.jpeg)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174204079/82IhNe-58.gif)

#### Random Forest Code with Python
