Skip to content

Commit

Permalink
random
Browse files Browse the repository at this point in the history
  • Loading branch information
PanduDcau authored Feb 18, 2024
1 parent 45ab919 commit 1fd67e7
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Random Forest/RandomForest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#installing Pre-request Packages
install.packages("stats")
install.packages("dplyr")
install.packages("randomForest")

#load required libraries
library(stats)
library(dplyr)
library(randomForest)

#loading the Data Objects
batsy = iris

#inspect Data
View(batsy)

#Variable Selection
str(batsy)

#Splitting data in Training Process and as well as Testing
#A Vector that has random sample of Training Values

black=sample(2,nrow(batsy),replace = TRUE ,prob = c(0.65,0.35))

#Let's do the Training
Training = batsy[black==1,]

#Testing Data
Testing= batsy[black==2,]

#Create Random Forest Model

RF = randomForest(Species~.,data = Training)

#Evaluating Model Accuracy
Species_Pred = predict(RF,Testing)
Testing$Species_Pred <- predict(RF,Testing)
TestSpec_pred = Species_Pred
View(Testing)

#Building Confusion Matrix
CM = table(Testing$Species, Testing$Species_Pred)
length(Testing$Species)
#length(Testing$Species_Pred)
CM

classification_Accuracy = sum(diag(CM)/sum(CM))
classification_Accuracy

0 comments on commit 1fd67e7

Please sign in to comment.