Original article was published on Deep Learning on Medium

# Python Implementation of SVM, Logistics Regression, Naive Bayes, Decision Tree, Random Forest using Scikit-learn (just 3 line of Code)

## Python Implementation of 5 Machine Learning Algorithm for Machine Learning Classification Problems

Hello Programmers!

Here I am gonna show How to Implement SVM, Logistics Regression, Naive Bayes, Decision Tree, Random Forest in Python using Scikit-learn or sklearn. And yeah this is too easy to implement, just write three lines of Python code, and you get your Decision Tree classifier.

Because this is beauty of

sklearn (Scikit-learn).

**Note:** You can get this notebook in my Github, I give you link below.

So let’s dirty our hands by some coding.

First we need a dataset, and I have a dataset of Market where you have to predict that customer purchasing item or not.

**What has in my Dataset?**

- Have three columns
- Age: Age of Person
- Estimated Salary: Salary of an individual
- Purchased: Customer buy or not

**Important Python Libraries:**

**Numpy**for handling arrays**Pandas**for creating DataFrame**Sklearn**for Machine Learning

## Installing Libraries Using *pip*

`#dependencies`

!pip install numpy

!pip install pandas

!pip install sklearn

## In [1]

**train_test_split**: Split arrays or matrices into random train and test subsets or you can say it split the dataset into train set and test set by 20%

`# Importing the libraries`

import numpy as np

import pandas as pd

# Importing the dataset

dataset = pd.read_csv('dataset.csv')

display(dataset.head())

X = dataset[['Age', 'EstimatedSalary']].values

y = dataset['Purchased'].values

print('-'*80)

print(f'Shape of X is {X.shape}\nShape of y is {y.shape}')

# Splitting the dataset into the Training set and Test set

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

print('-'*80)

print(f"Lenght of X_train: {len(X_train)}\nLenght of X_test: {len(X_test)}")

print(f"Lenght of y_train: {len(y_train)}\nLenght of y_test: {len(y_test)}")