Coders Packet

Classification Templates in Python

By Radhika Talwar

This packet contains Classification Python Model templates and the pros and cons of all the Different Classification models.

This packet contains Classification Python Model templates and the pros and cons of all the Different Classification models and can use these general templates by just changing the name of the dataset.

Classification is a kind of supervised learning which classifies the given data in categories. It specifies the category out all the available categories to which new data elements belong to and is best used when the output has discrete and finite values. It can predict a class for an input variable as well. Classification is of two types: Linear and Non-Linear Classifications. 

During Classification, We follow these steps:

1.Data Preprocessing:

In this, you import the libraries and import the dataset And will split the data into Training and Test Set. With the training set, we will train the machine, and then We will test our Machine on the Test set to check the accuracy and Feature Scaling is done on the data to get it in the range of -3 <= 0 <= 3.

2.Training the Machine

You Can train your machine with any Classification Model on the Training Set.

3.Predicting and Visualising the Result

In this, you can predict the result and can visualize it using the matplot Library so as to check the accuracy of the precited result on the test set and can check it on the Confuse matrix.

Classification is a type of supervised learning. It specifies the class to which data elements belong to and is best used when the output has finite and discrete values. It predicts a class for an input variable as well. Classification is of two types: Linear and Non-Linear Classifications.

1.Decision Tree Classification

A Decision Tree Classification uses trees to classify the categories. It is a Machine Learning Algorithm in which parameter and classified on the basis of the decision parameter. In the Decision Tree, you have to build categories of yes or no on the basis of deciding parameter mentioned in the tree.

from sklearn.tree import DecisionTreeClassifier
classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)
classifier.fit(X_train, y_train)

2.Naive Bayes Theorem

Naive Bayes is a model that is used for large amounts of data. It gives very good results when it comes to NLP tasks. It is a fast and easy classification algorithm. It can be used for Sentiment analysis.

It is based on Bayes Theorem.

from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)

3.K-Nearest neighbors Classification

K nearest neighbors is a Classification model that stores all cases from Training Set and classifies new cases based on a similarity measure. You have to choose N nearest neighbors and choose the one which category fits better yo it according to the algorithm. It should be completely discrete like it is an apple or pineapple. There is no middle possibility.

from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p = 2)
classifier.fit(X_train, y_train)

 

These are the Classification Algorithms you can refer to.

 

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Radhika Talwar (radhikatalwar62)

Download packets of source code on Coders Packet