python
Dashboard
My Repos
Compilers
Python Online
Node JS Online
Golang Online
codepy
Login
My Repos
Sign Out
Online Python Interpreter
Stop
Run
def predict(self, x): """Predict and return labels for each feature vector from x x -- feature vectors (N x D) """ predictions = [] # placeholder for N labels # loop over all test samples for x_test in x: # array of distances between current test and all training samples distances = np.sum(self.distance(self.x_train - x_test), axis=1) # get the closest one min_index = np.argmin(distances) # add corresponding label predictions.append(self.y_train[min_index]) return predictions
Share this code with others
Public
Clear
My Repos
Repo
Lang
Login
Register
Login
Create a free account. No Credit card info required.
I agree with the Codepy
Term of Service
Sign Up