Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'n_neighbors' is not defined #1

Open
fngwira14 opened this issue Dec 19, 2019 · 1 comment
Open

NameError: name 'n_neighbors' is not defined #1

fngwira14 opened this issue Dec 19, 2019 · 1 comment

Comments

@fngwira14
Copy link

Hallo @Francis515 ,

I was trying to run the KNN and i am receiving this error, please help out...
:::::::Code::::::::::
def knn_train_val(n_neighbors=5, train_sample_num = 2000, val_sample_num = 100, verbose=0):
# training data
x_train = np.zeros(shape=(train_sample_num, img_h * img_w * 3))
x_feature_train = np.zeros(shape=(train_sample_num, 64))
y_train = np.zeros(shape=(train_sample_num), dtype=np.uint8)
for i in range(train_sample_num):
x_feature_train[i] = (Ci.get_train_feature_Xi(i))
y_train[i] = (Ci.get_train_Yi(i))

:::::::Error Message::::::::::

NameError Traceback (most recent call last)
in
1 # classification
----> 2 knn = neighbors.KNeighborsClassifier(n_neighbors=n_neighbors)
3 knn.fit(x_feature_train, y_train)

NameError: name 'n_neighbors' is not defined

@Francis515
Copy link
Owner

Hi, I'm sorry I don't know what's wrong.
In the function knn_train_val, n_neighbors is a parameter. I don't think we need to define it.

Maybe you could change the name of that parameter and try again:
def knn_train_val( n=5, ...
...
knn = neighbors.KNeighborsClassifier(n_neighbors=n)

OR define a new variable to get the value of the parameter:
...
n = n_neighbors
knn = neighbors.KNeighborsClassifier(n_neighbors=n)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants