Applicazioni pratiche di machine learning/Previsioni sugli incendi: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 1:
{{avanzamento|75%|01 febbraio 2020}}
{{Applicazioni pratiche di machine learning}}
==Caricamento librerie==
 
Line 116 ⟶ 118:
 
== Parte 4: Modellizzazione e previsione==
 
Per creare un modello previsionale si utilizza la libreria "H2o" che consente con la sua funzione autoML di selezionare automaticamente l'algoritmo di machine learning migliore, cioè quello nel caso specifico che da un più basso valore dell'errore previsionale RMSE.
 
<syntaxhighlight lang="rsplus">
h2o.init()
</syntaxhighlight>
 
H2O is not running yet, starting it now...
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04, mixed mode, sharing)
Starting H2O JVM and connecting: ..... Connection successful!
R is connected to the H2O cluster:
H2O cluster uptime: 7 seconds 720 milliseconds
H2O cluster timezone: Europe/Rome
H2O data parsing timezone: UTC
H2O cluster version: 3.28.0.2
H2O cluster version age: 11 days
H2O cluster name: H2O_started_from_R_gian_wze918
H2O cluster total nodes: 1
H2O cluster total memory: 1.92 GB
H2O cluster total cores: 2
H2O cluster allowed cores: 2
H2O cluster healthy: TRUE
H2O Connection ip: localhost
H2O Connection port: 54321
H2O Connection proxy: NA
H2O Internal Security: FALSE
H2O API Extensions: Amazon S3, XGBoost, Algos, AutoML, Core V3, TargetEncoder, Core V4
R Version: R version 3.6.2 (2019-12-12)
Show in New WindowClear OutputExpand/Collapse Output
 
<syntaxhighlight lang="rsplus">
train <- h2o.importFile("forestfires.csv")
y <- "area"
x <- setdiff(names(train), y)
 
aml <- h2o.automl(x = x, y = y,
training_frame = train,
max_runtime_secs = 30)
</syntaxhighlight>
 
Di seguito in ordine i migliori algoritmi selezionati da H2o, tra cui il primo è GLM_1_AutoML_20200201_222130 cioè un algoritmo GLM (Generalized Linear Models)
 
<syntaxhighlight lang="rsplus">
lb <- aml@leaderboard
lb
</syntaxhighlight>
 
model_id mean_residual_deviance rmse
1 GLM_1_AutoML_20200201_222130 4045.990 63.60810
2 GBM_5_AutoML_20200201_222130 4055.079 63.67950
3 XGBoost_2_AutoML_20200201_222130 4064.721 63.75516
4 DeepLearning_1_AutoML_20200201_222130 4069.798 63.79497
5 XRT_1_AutoML_20200201_222130 4126.609 64.23869
6 StackedEnsemble_BestOfFamily_AutoML_20200201_222130 4133.725 64.29405
 
 
L'errore previsionale RMSE dell'algoritmo GLM selezionato è pari a 63,23 ettari...
 
<syntaxhighlight lang="rsplus">
model <- aml@leader
model
p1 = h2o.predict(model, newdata=train)
p1_df <- as.data.frame(p1)
cat("RMSE=",sqrt(mean((p1_df$predict-forestfires$area)^2)))
</syntaxhighlight>
 
RMSE= 63.23721
 
 
[[Categoria:Applicazioni pratiche di machine learning|Previsioni sugli incendi]]