Documentation for General Estimators¶
Build NARX Models Using general estimators.
NARX ¶
Bases: BaseMSS
NARX model build on top of general estimators.
The Nonlinear AutoRegressive with eXogenous inputs (NARX) model is mathematically described by:
where \(\mathbf{\phi}(t)\) is the regression vector composed of lagged inputs and outputs:
Here, \(n_y\) (ylag) and \(n_x\) (xlag) are the maximum lags for the output and input, respectively. The function \(F\) is approximated by the base estimator. For NARMAX models, the regression vector includes lagged residuals:
where \(n_e\) is determined by the basis function and model_type parameter.
This implementation uses GenerateRegressors and InformationMatrix to construct lagged features and allows infinite-step-ahead prediction via iterative methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ylag | int | The maximum lag order of the output \(n_y\) (number of past output terms used). | 2 |
xlag | int | The maximum lag order of the input \(n_x\) (number of past input terms used). | 2 |
fit_params | dict | Additional parameters to pass to the | None |
base_estimator | estimator object | An sklearn-compatible estimator with | None |
basis_function | basis function object | Nonlinear transformation applied to regressors (e.g., Polynomial, Fourier). | Polynomial |
model_type | (NARMAX, NAR, NFIR) | Model structure. Use "NARMAX" to include lagged residuals in the regression vector. | "NARMAX" |
Examples:
>>> import numpy as np
>>> from sysidentpy.general_estimators import NARX
>>> from sklearn.linear_model import BayesianRidge
>>> from sysidentpy.basis_function import Polynomial
>>> from sysidentpy.utils.generate_data import get_siso_data
>>> # Generate data and fit model
>>> x_train, x_valid, y_train, y_valid = get_siso_data(n=1000)
>>> basis_function = Polynomial(degree=2)
>>> model = NARX(
... base_estimator=BayesianRidge(),
... xlag=2,
... ylag=2,
... basis_function=basis_function,
... model_type="NARMAX"
... )
>>> model.fit(x_train, y_train)
>>> yhat = model.predict(x_valid, y_valid)
>>> # Evaluation and plotting code here
0.000131
Source code in sysidentpy/general_estimators/narx.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
fit(*, X=None, y=None) ¶
Train a NARX Neural Network model.
This is a training pipeline that allows a friendly usage by the user. All the lagged features are built using the SysIdentPy classes and we use the fit method of the base estimator of the sklearn to fit the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X | ndarrays of floats | The input data to be used in the training process. | None |
y | ndarrays of floats | The output data to be used in the training process. | None |
Returns:
| Name | Type | Description |
|---|---|---|
base_estimator | sklearn estimator | The model fitted. |
Source code in sysidentpy/general_estimators/narx.py
predict(*, X=None, y=None, steps_ahead=None, forecast_horizon=1) ¶
Return the predicted given an input and initial values.
The predict function allows a friendly usage by the user. Given a trained model, predict values given a new set of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X | ndarray of floats | The input data to be used in the prediction process. | None |
y | ndarray of floats | The output data to be used in the prediction process. | None |
steps_ahead | int(default=None) | The user can use free run simulation, one-step ahead prediction and n-step ahead prediction. | None |
forecast_horizon | int | Number of values predicted beyond the initial conditions for a NAR free-run prediction when | 1 |
Returns:
| Name | Type | Description |
|---|---|---|
yhat | ndarray of floats of shape (n_predictions, 1) | Predicted values including the initial conditions. |