I have created an ARX model using sysid function, and now I want to extrapolate this model for other inputs.
I firstly created this model and identified its parameters for a training subset of data.
m = GEKKO(remote=False)
na = n_a
nb = n_b
yp_train, p, K = m.sysid(t_train, u_train, y_train, na, nb)
Having this model fit is there any way i can use the same parameters and utilize them with different inputs ?
Here is what i was going for
def arxouriço2(df, inputs, outputs, n_a, n_b, train_slice=None, test_slice=None):
datafreime_arx = df.copy()
if isinstance(inputs, pd.Series):
inputs = pd.DataFrame(inputs)
if isinstance(outputs, pd.Series):
outputs = pd.DataFrame(outputs)
colunas_arx = list(inputs.columns) + list(outputs.columns)
mean_col = []
std_dev_col = []
for i in colunas_arx:
mean = np.nanmean(datafreime_arx[i])
mean_col.append(mean)
datafreime_arx[i] -= mean
std_dev = np.nanstd(datafreime_arx[i])
std_dev_col.append(std_dev)
datafreime_arx[i] /= std_dev
if train_slice is not None:
train_data = datafreime_arx.iloc[train_slice]
t_train = train_data['Tempo']
u_train = inputs.iloc[train_slice]
y_train = outputs.iloc[train_slice]
else:
t_train = datafreime_arx['Tempo']
u_train = inputs
y_train = outputs
if test_slice is not None:
test_data = datafreime_arx.iloc[test_slice]
t_test = test_data['Tempo']
u_test = inputs.iloc[test_slice]
y_test = outputs.iloc[test_slice]
else:
t_test = datafreime_arx['Tempo']
u_test = inputs
y_test = outputs
m = GEKKO(remote=False)
na = n_a
nb = n_b
yp_train, p, K = m.sysid(t_train, u_train, y_train, na, nb)
for i, col in enumerate(colunas_arx):
datafreime_arx[col] /= std_dev_col[i]
datafreime_arx[col] -= mean_col[i]
resis = y_train - yp_train
resis2 = resis ** 2
print('Sum of squared residuals: ' + str(np.sum(resis2)))
if test_slice is not None:
yp_test = m.sysid(t_test, u_test, y_test, na, nb)[0]
plt.figure(figsize=(8, 5))
plt.subplot(2, 1, 1)
plt.plot(t_train, u_train)
plt.legend(inputs.columns)
plt.ylabel('Temperature (ºC)')
plt.subplot(2, 1, 2)
plt.plot(t_test, y_test, label=outputs.columns)
plt.plot(t_test, yp_test, label=outputs.columns + ' predicted')
plt.legend()
plt.ylabel('Rotation (º)')
plt.xlabel('Time')
plt.tight_layout()
plt.show()
return p, K, m
arxouriço2(df_c3_avg5_c2,df_c3_avg5_c2[['STH3_avg','STH-04']],df_c3_avg5_c2['C14-Y'],10,10,range(465, 829),range(829, 903))

