Python codes for types of Classification Algorithms
These classification algorithms are used for the calculation of metrics accuracy of the data by using python.
The Classification algorithm is a Supervised Learning technique that is used to identify the category of new observations on the basis of training data. In Classification, a program learns from the given dataset or observations and then classifies new observation into a number of classes or groups
Classification can be performed on structured or unstructured data. Classification is a technique where we categorize data into a given number of classes. The main goal of a classification problem is to identify the category/class to which new data will fall.
“An algorithm must be seen to be believed”
Here are the few types of classification algorithms that are used in python:
- Decision Tree
- Logistic Regression
- Random Forest
Decision Tree:
Given a data of attributes together with its classes, a decision tree produces a sequence of rules that can be used to classify the data.
Code for the Decision Tree Classification in python
from sklearn.tree import DecisionTreeClassifier
dtree = DecisionTreeClassifier()
dtree=fit(x_train, x_train)
pre_y=dtree.predict(x_test)
Random Forest:
Random Forest classifier is a meta-estimator that fits a number of decision trees on various sub-samples of datasets and uses average to improve the predictive accuracy of the model and controls over-fitting. The sub-sample size is always the same as the original input sample size but the samples are drawn with replacement.
from sklearn.ensemble import RandomForestClassifier
rcm=RandomForestClassifier()
rcm=fit(x_train, x_train)
pre_y=rcm.predict(x_test)
Logistic regression:
Logistic regression is a machine learning algorithm for classification. In this algorithm, the probabilities describing the possible outcomes of a single trial are modeled using a logistic function.
from sklearn.linear_model import LogisticRegression
lr= LogisticRegression()
lr= fit(x_train, x_train)
pre_y=lr. Predict(x_test)
These are few codes for the classification of algorithms used in python.
Thanks for reading..!!