Facebook
From aa, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 261
  1. #dane z http://neuroph.sourceforge.net/tutorials/ForestFires/PredictingTheBurnedAreaOfForestFires.html
  2. #skróty z nazw tabel http://cwfis.cfs.nrcan.gc.ca/background/summary/fwi
  3.  
  4. #czyścimy
  5. gc(reset=T)
  6. rm(list = ls())
  7.  
  8. #ładujemy potrzebne biblioteki
  9. library ('dplyr')
  10. #pobieranie pliku
  11. path <-"D:/forestfire.csv"
  12. dane<-read.csv(path,header=TRUE,sep=";",dec=',')
  13. dane%>%subset(area<=40)%>%subset(area>0)->dane2
  14.  
  15. FindOutliers <- function(data) {
  16.   lowerq = quantile(data)[2]
  17.   upperq = quantile(data)[4]
  18.   iqr = upperq - lowerq #Or use IQR(data)
  19.   # we identify extreme outliers
  20.   extreme.threshold.upper = (iqr * 3) + upperq
  21.   extreme.threshold.lower = lowerq - (iqr * 3)
  22.   result <- which(data > extreme.threshold.upper | data < extreme.threshold.lower)
  23. }
  24.  
  25. temp <- FindOutliers(dane2$FFMC)
  26. dane2$FFMC[temp]<-NA
  27.  
  28. #histogram
  29. hist(dane2$area
  30.      ,col= 'green'#kolor histogramu
  31.      ,main='histogram obszaru spalonego'#nazwa histogramu
  32.      ,xlab='area'#nazwa x-owej
  33.      ,ylab='liczba wystapien')#nazwa y-kowej
  34.  
  35. #korelacja
  36. dane2%>%select_("area", "FFMC","DMC","DC","ISI"  ,        
  37.                "temp","RH","wind","rain")->dane_cov
  38. CORELATIONS <- cor(dane_cov, method="pearson", use="complete.obs")
  39. round(CORELATIONS,3)->CORELATIONS
  40. library(corrplot)
  41. corrplot(CORELATIONS, type="lower", tl.col="black", tl.srt=45)
  42.  
  43. #wkresy zależności
  44. plot(dane2$area, dane2$temp,
  45.      col="black",pch=21,bg="red",cex=2,ylab="",xlab="",
  46.      axes=TRUE,main="Zaleznosc obszaru spalonego od temperatury")
  47. mtext('area', side=1,line=2.5,cex=1.5)
  48. mtext('temp', side=2,line=2.5,cex=1.5)
  49. abline(linear_model, lty=5,lwd=2, col="blue")
  50.  
  51. plot(dane2$area, dane2$FFMC,
  52.      col="black",pch=21,bg="red",cex=2,ylab="",xlab="",
  53.      axes=TRUE,main="Zaleznosc obszaru spalonego od indexu ffmc")
  54. mtext('area', side=1,line=2.5,cex=1.5)
  55. mtext('FFMC', side=2,line=2.5,cex=1.5)
  56.  
  57. plot(dane2$area, dane2$DMC,
  58.      col="black",pch=21,bg="red",cex=2,ylab="",xlab="",
  59.      axes=TRUE,main="Zaleznosc area od DMC")
  60. mtext('area', side=1,line=2.5,cex=1.5)
  61. mtext('RH', side=2,line=2.5,cex=1.5)
  62.  
  63. plot(dane2$ISI, dane2$FFMC,
  64.      col="black",pch=21,bg="red",cex=2,ylab="",xlab="",
  65.      axes=TRUE,main="Zaleznosc isi od indexu ffmc")
  66. mtext('ISI', side=1,line=2.5,cex=1.5)
  67. mtext('FFMC', side=2,line=2.5,cex=1.5)
  68.  
  69. plot(dane2$temp, dane2$RH,
  70.      col="black",pch=21,bg="red",cex=2,ylab="",xlab="",
  71.      axes=TRUE,main="Zaleznosc temp od rh")
  72. mtext('temp', side=1,line=2.5,cex=1.5)
  73. mtext('RH', side=2,line=2.5,cex=1.5)
  74.  
  75. #regresja liniowa
  76. fit1 = lm(formula = dane2$area ~ dane2$temp)
  77. summary(fit1)
  78. plot(dane2$area,predict(fit1))
  79. abline(fit1)
  80.  
  81. #regresja wielowymiarowa
  82.