python-3.x knn.fit(X_train,y_train)未显示参数

fcg9iug3  于 2023-02-26  发布在  Python
关注(0)|答案(1)|浏览(160)

它显示的输出如下所示。
enter image description here
我期望输出为:

`KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',
metric_params=None, n_jobs=1, n_neighbors=1, p=2,
weights='uniform')`

当我正在阅读O'Reilly的《机器学习与Python》一书时。

jdgnovmf

jdgnovmf1#

只需对拟合对象使用get_params方法。

from sklearn.neighbors import KNeighborsClassifier

X = [[0], [1], [2], [3]]
y = [0, 0, 1, 1]

neigh = KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski', metric_params=None, n_jobs=1, n_neighbors=1, p=2, weights='uniform')
neigh.fit(X, y)

neigh.get_params()
{'algorithm': 'auto',
 'leaf_size': 30,
 'metric': 'minkowski',
 'metric_params': None,
 'n_jobs': 1,
 'n_neighbors': 1,
 'p': 2,
 'weights': 'uniform'}

相关问题