Search code examples
python-3.xscikit-learnknn

knn.fit(X_train, y_train) not showing parameters


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.


Solution

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