707 views
1 1 vote

I have this question as an assignment, I am having challenges in interpreting this question.

Q4. Define a function that takes a 1-d numpy array, a parameter k, and a number p. The function returns an estimate equal to the mean of the closest k points to the number p

The challenge I have is, kNN seems to work for multi-dimensional arrays. howver, here this is a single D array.

Am i to write the function from scratch to loop through this single D array to find the closest numbers to the number P (from this singleD array?) In which case I need not use the kNN libraries, but use my own logic.

I am not exactly looking for the answer, but am looking for clarification.

Thank you

RSH

0% Accept Rate Accepted 0 answers out of 2 questions

1 Answer

0 0 votes
You can use rshape function like: input_data.reshape(-1, 1)

Related questions

1 1 vote
1 1 answer
3.2k
3.2k views
RSH asked Oct 1, 2018
3,240 views
I am not able to figure out how the calculation of the $m$ nearest points will be in a single dimensional array using kNN. Can anyone offer a clue or example?Thank you
1 1 vote
1 answers 1 answer
4.9k
4.9k views
tofighi asked Feb 18, 2020
4,920 views
Assuming we have a linear regression equation and some data points (sample), how can we calculate residual error for each data point, and total cost based on the metrics ...
1 1 vote
1 1 answer
9.4k
9.4k views
1 1 vote
1 1 answer
780
780 views
Harsh Grover asked May 16, 2019
780 views
Make a scatter plot where the x-axis is the height of the citizens and the y-axis is the weight of the citizens. The color of the points need to be different for males an...
1 1 vote
1 1 answer
2.7k
2.7k views
engy.abdelazeez asked Apr 3, 2019
2,685 views
I preprocessed the data, normalized the numerical features, and did one hot encoding for the categorical ones. I end up with a model with R^2=0.7 and RMSE which is 15% of...