[R] Help Required for R Markdown function.
Kishor raut
r@utk|@hor01 @end|ng |rom gm@||@com
Sat Feb 27 12:47:53 CET 2021
Respected Sir,
I Mr Kishor Tried to get help online but wont found the solution so
writting an email.
Step1: While writting in rmarkdown all codes get executted very well till
the fuction
Confusionmatrix were written on it.
Step2: As confusionmatrix command inserted following error is on screen
board
processing file: RMarkdown.Rmd
|..... |
7%
ordinary text without R code
|......... |
13%
label: unnamed-chunk-1
|.............. |
20%
ordinary text without R code
|................... |
27%
label: unnamed-chunk-2
|....................... |
33%
ordinary text without R code
|............................ |
40%
label: unnamed-chunk-3
|................................. |
47%
ordinary text without R code
|..................................... |
53%
label: unnamed-chunk-4
|.......................................... |
60%
ordinary text without R code
|............................................... |
67%
label: unnamed-chunk-5
|................................................... |
73%
ordinary text without R code
|........................................................ |
80%
label: unnamed-chunk-6
|............................................................. |
87%
ordinary text without R code
|................................................................. |
93%
label: unnamed-chunk-7
Quitting from lines 98-104 (RMarkdown.Rmd)
Error in confusionMatrix(p1, train$CTestresult) :
could not find function "confusionMatrix"
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval
-> eval
Execution halted
Step4: As codes were written these
Using function “sample” the data takes into sample of the specified size
from the stored data
```{r}
set.seed(1234)
ind<-sample(2,nrow(FEVER1),replace=TRUE, pro = c(0.7,0.3))
train<-FEVER1[ind==1,]
test<-FEVER1[ind==2,]
```
Application of Random Forest
```{r}
library(randomForest)
set.seed(123)
rfmodel<-randomForest(CTestresult~.,data = train,prox=TRUE) # Random
Forest Model
plot(rfmodel,main="RandomForest Model")
print(rfmodel,train) # Printing Outcome of 'model for
Training Data
```
Prediction using Randome Forest Model
```{r}
# Prediction of RandomForest Intial Model for Test and Train Data
ptrain1<-predict(rfmodel,train) # Predicting model Prediction
On Training Data
# First Six Outcomes with prediction
head(ptrain1) # Printing First Six Prediction
using Random Forest Model
head(train$CTestresult) # Printing First Six (6)
Actual outcomes
```
Tuning Model:
Tuning of Machine learning model is important step for building good model
for best outcome of research.
```{r}
# Tunning RandomForest Model using Algorithm
t<-tuneRF(train[,-11],train$CTestresult, mtryStart = 2,ntreeTry = 100,
stepFactor =2,improve = 0.051,trace = TRUE, plot = TRUE, doBest=TRUE)
```
Building New Model:
New model was build on the basis of tunned model parameters and controls.
```{r}
# New Model After Tuning Random Forest Model
rf1<-randomForest(CTestresult~.,data = train,ntree = 100, mtry = 8,
importance = TRUE,proximity = TRUE)
print(rf1)
```
Prediction and Confusion MAtrix:
outcome of model will mesuare with the help of predictive outcomes with the
help of confusion matrix.
```{r}
# Prediction using Random Forest and Confusion Matrix for Train Data
p1<-predict(rf1,train)
cmatrix<-confusionMatrix(p1,train$CTestresult)
cmatrix
```
I will great thank full if you will help me for to remove the error.
--
*Kind Regards*
Kishor Raut
*Cell No.-07387706552*
[[alternative HTML version deleted]]
More information about the R-help
mailing list