-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Description
I follow the tutorial in (https://pysal.org/notebooks/model/mgwr/GWR_prediction_example.html)
using gaopandas and sample to split the test and train set.
gdf = data_geo.to_crs('EPSG:27700')
gdf_train = gdf.sample(frac=0.8, axis=0, random_state=RANDOM_SEED)
gdf_test = gdf[~gdf.index.isin(gdf_train.index)]
X_train = gdf_train.drop(['Y', 'geometry'], axis=1).values
y_train = gdf_train['Y'].values.reshape((-1,1))
u = gdf_train.geometry.x
v = gdf_train.geometry.y
coords_train = list(zip(u,v))
selector = Sel_BW(coords, y_train, X_train)
gwr_bw = selector.search()
print('GWR bandwidth =', gwr_bw)
model = GWR(coords_train, y_train, X_train, gwr_bw)
gwr_results = model.fit()
X_test = gdf_test.drop(['Y', 'geometry'], axis=1).values
y_test = gdf_test['Y'].values.reshape((-1,1))
u = gdf_test.geometry.x
v = gdf_test.geometry.y
coords_test = np.array(list(zip(u,v))) # https://github.com/pysal/mgwr/issues/85
scale = gwr_results.scale
residuals = gwr_results.resid_response
pred_results = model.predict(coords_test, X_test, scale, residuals)Currently, it works well. But when I want to print the prediction result.
pred_results.predictionsit shows the
Caution
ValueError: operands could not be broadcast together with shapes (201,106) (201,103)
How to fix it, I want to check the R2 of the predicted results.
Metadata
Metadata
Assignees
Labels
No labels