library(MASS) Jussac=read.table('Jussac.data.txt',header=TRUE) Jussac.learn=data.frame(Jussac[-43,]) Z=rep("Chien",42) Z[Jussac.learn[,1]=="Loup"]="Loup" Jussac.learn[,1]=as.factor(Z) Type.lda <- lda(Type~., data=Jussac.learn) LD1 <- Type.lda$scaling[,1] proj=as.matrix(Jussac.learn[,-1])%*%LD1 plot(proj,Z=='Chien',xlab='LD1',ylab='Type',col=(Z=='Chien')+1,yaxt="n") axis(2,at=c(0,1),c('Loup','Chien')) Type=Z CV=lda(Type~., data=Jussac.learn,CV=TRUE) Classe_est=CV$class table(Type,Classe_est) mean(Classe_est!=Type) Prob=CV$posterior[,1] g=c(0,sort(unique(Prob)),1) TFP=rep(NA,length(g)) TVP=rep(NA,length(g)) for (i in 1:length(g)) { TFP[i]=mean(Prob[Type=='Loup']>g[i]) TVP[i]=mean(Prob[Type=='Chien']>g[i]) } plot(TFP,TVP,type='l',main='Courbe ROC',col='blue') polygon(c(1,TFP,0), c(0,TVP,0), col="blue") abline(0,1,col='red') predict(Type.lda,Jussac[43,-1])$class predict(Type.lda,Jussac[43,-1])$posterior[1] ampTFP=TFP[-length(TFP)]-TFP[-1] AUC=sum(ampTFP*TVP[-length(TVP)]) library(plotly) p=plot_ly(x=~TFP,y=~TVP,type = 'scatter',mode='lines',fill = 'tozeroy') add_lines(p,x=~TFP,y=~TFP,name='y=x',color=I('orange'))