knn.fit(X_train, y_train)不显示参数

huangapple go评论58阅读模式
英文:

knn.fit(X_train, y_train) not showing parameters

问题

以下是翻译好的部分:

The output it shows, is below.
输出如下。

I expected the output to be:
我预期的输出应该是:

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

As I am working through the book introduction to machine learning with Python by O'Reilly.
因为我正在阅读 O'Reilly 出版的《Python 机器学习入门》这本书。

英文:

The output it shows, is below.

enter image description here

I expected the output to be:

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

As I am working through the book introduction to machine learning with Python by O'Reilly.

答案1

得分: 0

只需在已拟合的对象上使用 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'}
英文:

Just use the get_params method on the fitted object.

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'}

huangapple
  • 本文由 发表于 2023年2月23日 19:48:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544427.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定