Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add distance attribute to knn weights #762

Open
lanselin opened this issue Aug 8, 2024 · 4 comments
Open

add distance attribute to knn weights #762

lanselin opened this issue Aug 8, 2024 · 4 comments

Comments

@lanselin
Copy link
Member

lanselin commented Aug 8, 2024

It would be nice if the KNN weights object also included a distance attribute in addition to neighbors and weights. The weights are all 1, which is not informative. In contrast, distance band weights have a binary argument, which if False gives the distance raised to a power.

I believe it would not necessitate any additional calculations. As an example, consider the GWT k-nearest neighbor weights created by GeoDa. Also, sklearn.neighbors KDTree already contains the distances.

@martinfleis
Copy link
Member

As noted in #763, this is already possible, just using the kernel builder instead of KNN.

With Graph:

Graph.build_kernel(df, k=5, kernel="identity")
# or
Graph.build_kernel(df, k=5, kernel=None)

With W:

weights.Kernel.from_dataframe(df, k=5, kernel="identity")

@lanselin
Copy link
Member Author

lanselin commented Aug 8, 2024

The kernel="identity" argument is not documented in the API documentation for weights.Kernel. Under libpysal.weights.Kernel class method from_dataframe there is no mention of a "kernel" argument., the argument is "function", but maybe that is something different. Please clarify the docs, that is the first point of contact for many users.

@ljwolf
Copy link
Member

ljwolf commented Aug 8, 2024

Maybe I'm misreading this, but I don't think that the identity kernel is supported for the old W class.

@martinfleis
Copy link
Member

I honestly believed that the graph kernel API is just a mirror of weights in this case. My mistake, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants