Train the Model
The Spatial Error model introduces a spatial lag in the error term of the regression equation. By adding the spatial lag in the residual, the neighbors' errors influence the observation error.
The following code creates an instance of SpatialErrorRegressor
and
trains the model using a Spatial Pipeline with a preprocessing step to standardize
the data.
from oraclesai.regression import SpatialErrorRegressor
from oraclesai.pipeline import SpatialPipeline
from sklearn.preprocessing import StandardScaler
# Create the instance of SpatialErrorRegressor
spatial_error_model = SpatialErrorRegressor(spatial_weights_definition=weights_definition)
# Add the regressor to a spatial pipeline along with a pre-processing step
spatial_error_pipeline = SpatialPipeline([("scaler", StandardScaler()), ("spatial_error", spatial_error_model)])
# Train the Spatial Error model
spatial_error_pipeline.fit(X_train, "MEDIAN_INCOME")
The summary
property of a regressor displays different statistics of
the model and the estimated parameters. The following code gets the trained model
and prints its summary.
# Get the trained model
error_model_fit = spatial_error_pipeline.named_steps["spatial_error"]
# Print the summary of the trained model
print(error_model_fit.summary)
REGRESSION
----------
SUMMARY OF OUTPUT: MAXIMUM LIKELIHOOD SPATIAL ERROR (METHOD = FULL)
-------------------------------------------------------------------
Data set : unknown
Weights matrix : unknown
Dependent Variable : dep_var Number of Observations: 2475
Mean dependent var : 69640.3568 Number of Variables : 5
S.D. dependent var : 39961.9492 Degrees of Freedom : 2470
Pseudo R-squared : 0.6285
Sigma-square ML :454661980.170 Log likelihood : -28246.730
S.E of regression : 21322.804 Akaike info criterion : 56503.460
Schwarz criterion : 56532.530
------------------------------------------------------------------------------------
Variable Coefficient Std.Error z-Statistic Probability
------------------------------------------------------------------------------------
CONSTANT 70782.1082416 1248.2789978 56.7037564 0.0000000
MEAN_AGE 2575.5035983 588.8525955 4.3737662 0.0000122
MEAN_EDUCATION_LEVEL 11051.5768223 1050.1057765 10.5242511 0.0000000
HOUSE_VALUE 19081.0829838 814.4699114 23.4276094 0.0000000
INTERNET 7640.9119411 682.4557729 11.1962009 0.0000000
lambda 0.6563181 0.0239453 27.4090149 0.0000000
------------------------------------------------------------------------------------
================================ END OF REPORT =====================================