Questo e' un tentativo di applicazione di AutoKeras (AutoML ovvero machine learning automatizzato basato su Keras) ai dati del post precedente
La differenza sostanziale e' che la dimensione del train set deve essere un multiplo intero della batch size (in questo caso 42 e 4200)
# -*- coding: utf-8 -*-
"""Autokeras timeseries_forecaster
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1mQHWTqwyRKhShtTrwNXBvPHgOkU4ghsX
"""
!pip install autokeras
import pandas as pd
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import autokeras as ak
!rm detrend2.csv
!wget http://c1p81.altervista.org/detrend2.zip
!unzip detrend2.zip
dataset=pd.read_csv(r'detrend2.csv', sep=',')
# cancella la prima colonna del tempo
#dataset_c.drop('Data',axis=1,inplace=True)
dataset= dataset_c[1:6001]
dataset.head()
dataset.shape
val_split = int(len(dataset) * 0.7)
data_train = dataset[:val_split]
validation_data = dataset[val_split:]
data_x = data_train[
[
"Est.[mm]"
]
].astype("float64")
data_x_val = validation_data[
[
"Est.[mm]"
]
].astype("float64")
# Data with train data and the unseen data from subsequent time steps.
data_x_test = dataset[
[
"Est.[mm]"
]
].astype("float64")
data_y = data_train["Est.[mm]"].astype("float64")
data_y_val = validation_data["Est.[mm]"].astype("float64")
##print(data_x.shape)
#print(data_y.shape)
#print(data_y)
#la batch size deve essere un divisore
#della serie di train altrimenti genera errore
predict_from = 1
#lunghezza dei dati nel futuro
predict_until = 42
lookback = 30
clf = ak.TimeseriesForecaster(
lookback=lookback,
predict_from=predict_from,
predict_until=predict_until,
max_trials=4,
objective="val_loss",
)
clf.fit(
x=data_x,
y=data_y,
validation_data=(data_x_val, data_y_val),
batch_size=42,
epochs=20
)
# Predizione
predictions = clf.predict(data_x_test)
print(predictions.shape)
print(data_x_val.shape)
print(data_y_val.shape)
loss,acc = clf.evaluate(data_x_val, data_y_val, batch_size=42, verbose=1)
print('Accuracy: %.3f' % acc)
plt.plot(predictions)
plt.title("Estensimetro")
plt.xlabel('')
plt.ylabel('')
plt.show()
model = clf.export_model()
# summarize the loaded model
model.summary()
# save the best performing model to file
model.save('model_sonar.h5')