Knn give more weight to specific feature in distance

前端 未结 2 401
借酒劲吻你
借酒劲吻你 2020-12-22 07:17

I\'m using the Kobe Bryant Dataset. I wish to predict the shot_made_flag with KnnRegressor.

I\'ve used game_date to extract year and

2条回答
  •  北海茫月
    2020-12-22 07:42

    Just add on Shihab's answer regarding distance computation. Can use scipy pdist as suggested in this post, which is faster and more efficient.

    from scipy.spatial.distance import pdist, minkowski, squareform
    
    # create the custom weight array
    weight = ...
    # calculate pairwise distances, using Minkowski norm with custom weights
    distances = pdist(X, minkowski, 2, weight)
    # reformat the result as a square matrix
    distances_as_2d_matrix = squareform(distances)
    

提交回复
热议问题