Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------------------
- ValueError Traceback (most recent call last)
- D:\Users\psalm\AppData\Local\Temp/ipykernel_41176/1088380155.py in <module>
- 9 knn_regr.fit(x_train, y_train)
- 10 print("Performance of kNN regressor")
- ---> 11 breast_cancer_y_pred = knn_regr.predict(x_test)
- 12 print("Mean squared error: %.2f" % mean_squared_error(y_test, breast_cancer_y_pred))
- 13 print("Coefficient of determination: %.2f" % r2_score(y_test, breast_cancer_y_pred))
- C:\ProgramData\Anaconda3\lib\site-packages\sklearn\neighbors\_regression.py in predict(self, X)
- 206 X = check_array(X, accept_sparse='csr')
- 207
- --> 208 neigh_dist, neigh_ind = self.kneighbors(X)
- 209
- 210 weights = _get_weights(neigh_dist, self.weights)
- C:\ProgramData\Anaconda3\lib\site-packages\sklearn\neighbors\_base.py in kneighbors(self, X, n_neighbors, return_distance)
- 703 kwds = self.effective_metric_params_
- 704
- --> 705 chunked_results = list(pairwise_distances_chunked(
- 706 X, self._fit_X, reduce_func=reduce_func,
- 707 metric=self.effective_metric_, n_jobs=n_jobs,
- C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in pairwise_distances_chunked(X, Y, reduce_func, metric, n_jobs, working_memory, **kwds)
- 1621 else:
- 1622 X_chunk = X[sl]
- -> 1623 D_chunk = pairwise_distances(X_chunk, Y, metric=metric,
- 1624 n_jobs=n_jobs, **kwds)
- 1625 if ((X is Y or Y is None)
- C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
- 61 extra_args = len(args) - len(all_args)
- 62 if extra_args <= 0:
- ---> 63 return f(*args, **kwargs)
- 64
- 65 # extra_args > 0
- [9:29 PM]
- C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in pairwise_distances(X, Y, metric, n_jobs, force_all_finite, **kwds)
- 1788 func = partial(distance.cdist, metric=metric, **kwds)
- 1789
- -> 1790 return _parallel_pairwise(X, Y, func, n_jobs, **kwds)
- 1791
- 1792
- C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in _parallel_pairwise(X, Y, func, n_jobs, **kwds)
- 1357
- 1358 if effective_n_jobs(n_jobs) == 1:
- -> 1359 return func(X, Y, **kwds)
- 1360
- 1361 # enforce a threading backend to prevent data communication overhead
- C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in _pairwise_callable(X, Y, metric, force_all_finite, **kwds)
- 1401 iterator = itertools.product(range(X.shape[0]), range(Y.shape[0]))
- 1402 for i, j in iterator:
- -> 1403 out[i, j] = metric(X[i], Y[j], **kwds)
- 1404
- 1405 return out
- D:\Users\psalm\AppData\Local\Temp/ipykernel_41176/1088380155.py in mydist(x, y)
- 3 # a distance metric function applying different weights for different features
- 4 def mydist(x, y):
- ----> 5 return np.sum((x-y)**2 * np.array([0.75, 0.05, 0.03, 0.01, 0.01, 0.15, 0.05, 0.02]))
- 6
- 7 knn_regr = KNeighborsRegressor(n_neighbors=10, metric=mydist)
- ValueError: operands could not be broadcast together with shapes (30,) (8,)
Advertisement
Add Comment
Please, Sign In to add comment