To write a python program to perform random classification.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Google Colab /Jupiter Notebook
Random classifier: It creates a set of decision trees from randomly selected subset of training set. It then aggregates the votes from different decision trees to decide the final class of the test object. Random Forest is suitable for situations when we have a large dataset, and interpretability is not a major concern.
Purpose of Random classifier: One of the most important features of the Random Forest Algorithm is that it can handle the data set containing continuous variables as in the case of regression and categorical variables as in the case of classification.
- In Random forest n number of random records are taken from the data set having k number of records.
- Individual decision trees are constructed for each sample.
- Each decision tree will generate an output.
- Final output is considered based on Majority Voting or Averaging for Classification and regression respectively.
python
#Program to implement random classification. #Developed by : Vigneshwar S #Register Number : 212220230058
import matplotlib.pyplot as plt from sklearn import datasets x,y=datasets.make_blobs(n_samples=100,n_features=2,centers=2,cluster_std=1.05,random_state=2) fig=plt.figure(figsize=(10,8)) plt.plot(x[:,0][y==0],x[:,1][y==0],'r^') plt.plot(x[:,0][y==1],x[:,1][y==1],'bs') plt.xlabel("feature 1") plt.ylabel("feature 2") plt.title('Random Classification Data with 2 classes')
Thus the random classifier was successfully implemented using python programming.