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

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

knn.fit(X_train, y_train) not showing parameters

问题

以下是翻译好的部分:

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

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

  1. `KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',
  2. metric_params=None, n_jobs=1, n_neighbors=1, p=2,
  3. 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:

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

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

答案1

得分: 0

只需在已拟合的对象上使用 get_params 方法。

  1. from sklearn.neighbors import KNeighborsClassifier
  2. X = [[0], [1], [2], [3]]
  3. y = [0, 0, 1, 1]
  4. neigh = KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski', metric_params=None, n_jobs=1, n_neighbors=1, p=2, weights='uniform')
  5. neigh.fit(X, y)
  6. neigh.get_params()
  1. {'algorithm': 'auto',
  2. 'leaf_size': 30,
  3. 'metric': 'minkowski',
  4. 'metric_params': None,
  5. 'n_jobs': 1,
  6. 'n_neighbors': 1,
  7. 'p': 2,
  8. 'weights': 'uniform'}
英文:

Just use the get_params method on the fitted object.

  1. from sklearn.neighbors import KNeighborsClassifier
  2. X = [[0], [1], [2], [3]]
  3. y = [0, 0, 1, 1]
  4. neigh = KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski', metric_params=None, n_jobs=1, n_neighbors=1, p=2, weights='uniform')
  5. neigh.fit(X, y)
  6. neigh.get_params()
  1. {'algorithm': 'auto',
  2. 'leaf_size': 30,
  3. 'metric': 'minkowski',
  4. 'metric_params': None,
  5. 'n_jobs': 1,
  6. 'n_neighbors': 1,
  7. 'p': 2,
  8. '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:

确定