Skip to content

'operands could not be broadcast together with shapes' when using 'pred_results.predictions' #152

@X-Fan-Jack

Description

@X-Fan-Jack

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.predictions

it 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions