【KNN】sklearn.neighbors.KNeighborsClassifier的参数说明

class sklearn.neighbors.KNeighborsClassifier(n_neighbors=5, weights=’uniform’, algorithm=’auto’, leaf_size=30,p=2, metric=’minkowski’, metric_params=None, n_jobs=1, **kwargs)

参数说明:

  1. n_neighbors : int, optional (default = 5)
    Number of neighbors to use by default for kneighbors queries…

  2. weights : str or callable, optional (default = ‘uniform’)
    weight function used in prediction. Possible values::

    • ‘uniform’ : uniform weights. All points in each neighborhood are weighted equally.
    • ‘distance’ : weight points by the inverse of their distance. in this case, closer neighbors of a query point will have a greater influence than neighbors which are further away.
    • [callable] : a user-defined function which accepts an array of distances, and returns an array of the same shape containing the weights.
  3. algorithm : {‘auto’, ‘ball_tree’, ‘kd_tree’, ‘brute’}, optional
    Algorithm used to compute the nearest neighbors:

    • ‘ball_tree’ will use BallTree
      ‘kd_tree’ will use KDTree
      ‘brute’ will use a brute-force search.
      ‘auto’ will attempt to decide the most appropriate algorithm based on the values passed to fit method.
      Note: fitting on sparse input will override the setting of this parameter, using brute force.
  4. leaf_size : int, optional (default = 30)
    Leaf size passed to BallTree or KDTree. This can affect the speed of the construction and query, as well as the memory required to store the tree. The optimal value depends on the nature of the problem.

  5. p : integer, optional (default = 2)
    Power parameter for the Minkowski metric. When p = 1, this is equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.

  6. metric : string or callable, default ‘minkowski’
    the distance metric to use for the tree. The default metric is minkowski, and with p=2 is equivalent to the standard Euclidean metric. See the documentation of the DistanceMetric class for a list of available metrics.

  7. metric_params : dict, optional (default = None)
    Additional keyword arguments for the metric function.

  8. n_jobs : int or None, optional (default=None)
    The number of parallel jobs to run for neighbors search. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details. Doesn’t affect fit method.

【说明】

使用自动搜索调参的方法,可以调试的参数有(新手调试,如有建议,可以留言,我来测试效果,再完善文章,感谢!):

  • n_neighbors :一般也不需要更改,默认5是最佳的。也可以尝试在小范围调试看看效果。
  • leaf_size:一般默认是30。可以在其值不大的范围内调试看看效果。
  • weights :参数有‘uniform’和‘distance’,可以选择调试。

其他的参数默认即可。

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Xhfei1224

你的鼓励将是我创作的最大动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值