KNeighborsRegressor fit syntax - first argument needs extra brackets?

Hi all,
Hopefully quick question about the first argument of KNeighborsRegressor.fit(). First, links to the DQ screen in question and the documentation for the KNeighborsRegressor.fit() function.

Screen Link: Cross Validation 2/10
SciKit Documentation: KNeighborsRegressor.fit(X, y)


When I pass the following arguments:
X = training_set['column'] (One set of brackets),
y = training_set['true value column']

This error is thrown:
ValueError: Found input variables with inconsistent numbers of samples: [1, n]

Where n is the number of elements in the training set. But when I pass:
X = training_set[['column']] (Two sets of brackets)
y = training_set['true value column']

It works without complaint.

My guess is that KNeighborsRegressor treats X = training_set['column'] as a single element, whereas it treats X = training_set[['column]] as the actual column of data (as intended).

Am I missing something obvious here?
Thanks in advance for your help,
–Jack

Why double brackets? - #2 by the_doctor probably will answer your question.

1 Like

Thanks so much. Sorry for the repost.