Hi,
my question was whether the 'distance' function used for weighting returns the
Minkowski distance as defined in Wikipedia, or instead the p-th power of it.
For the p=2 which is treated separately I see in the neighbors/base.py source
file (class KNeighborsMixin)
elif self.p == 2:
dist = pairwise_distances(X, self._fit_X, 'euclidean',
squared=True)
(which gave me some doubt) and then a few lines later
if self.p == 2:
return np.sqrt(dist[j, neigh_ind]), neigh_ind
seems to indicate we do get the Euclidean distance rather than the square of it
(which is good…).
Should the corresponding case hold for other p values?
Thanks, Tom
--
-----------------------------------------
Institute for Gravitational Physics
(Albert Einstein Institute)
Callinstr. 38
D-30167 Hannover, Germany
On Jan 21, 2013, at 8:57 PM, Willi Richert wrote:
> Yes, it is the parameter p in the Minkowski distance:
> http://en.wikipedia.org/wiki/Minkowski_distance.
>
> I think the master branch should have this information in the docs.
>
>
> 2013/1/21 Thomas Dent <[email protected]>
> Hi all,
>
> I just started using sklearn nearest-neighbors for classification & would
> like to apply my own distance weighting function.
>
> To do this I need to know exactly what the 'distance' that is fed to the
> function represents. (Current documentation doesn't give me an immediate
> answer.)
>
> For example if I set p=2 do I get the Euclidean distance, i.e. the square
> root of the sums of squares of coordinate differences; or the square of it?
>
> If p>2 do I get the distance, in the sense of the p-th root of sum of p-th
> powers, or the p-th power of distance?
>
> Thanks,
> Tom
>
> --
> -----------------------------------------
> Institute for Gravitational Physics
> (Albert Einstein Institute)
> Callinstr. 38
> D-30167 Hannover, Germany
>
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. SALE $99.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122412
> _______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. SALE $99.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122412_______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general