john_1726

Untitled

Jun 27th, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. ---------------------------------------------------------------------------
  2. ValueError Traceback (most recent call last)
  3. D:\Users\psalm\AppData\Local\Temp/ipykernel_41176/1088380155.py in <module>
  4. 9 knn_regr.fit(x_train, y_train)
  5. 10 print("Performance of kNN regressor")
  6. ---> 11 breast_cancer_y_pred = knn_regr.predict(x_test)
  7. 12 print("Mean squared error: %.2f" % mean_squared_error(y_test, breast_cancer_y_pred))
  8. 13 print("Coefficient of determination: %.2f" % r2_score(y_test, breast_cancer_y_pred))
  9.  
  10. C:\ProgramData\Anaconda3\lib\site-packages\sklearn\neighbors\_regression.py in predict(self, X)
  11. 206 X = check_array(X, accept_sparse='csr')
  12. 207
  13. --> 208 neigh_dist, neigh_ind = self.kneighbors(X)
  14. 209
  15. 210 weights = _get_weights(neigh_dist, self.weights)
  16.  
  17. C:\ProgramData\Anaconda3\lib\site-packages\sklearn\neighbors\_base.py in kneighbors(self, X, n_neighbors, return_distance)
  18. 703 kwds = self.effective_metric_params_
  19. 704
  20. --> 705 chunked_results = list(pairwise_distances_chunked(
  21. 706 X, self._fit_X, reduce_func=reduce_func,
  22. 707 metric=self.effective_metric_, n_jobs=n_jobs,
  23.  
  24. C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in pairwise_distances_chunked(X, Y, reduce_func, metric, n_jobs, working_memory, **kwds)
  25. 1621 else:
  26. 1622 X_chunk = X[sl]
  27. -> 1623 D_chunk = pairwise_distances(X_chunk, Y, metric=metric,
  28. 1624 n_jobs=n_jobs, **kwds)
  29. 1625 if ((X is Y or Y is None)
  30.  
  31. C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
  32. 61 extra_args = len(args) - len(all_args)
  33. 62 if extra_args <= 0:
  34. ---> 63 return f(*args, **kwargs)
  35. 64
  36. 65 # extra_args > 0
  37. [9:29 PM]
  38. C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in pairwise_distances(X, Y, metric, n_jobs, force_all_finite, **kwds)
  39. 1788 func = partial(distance.cdist, metric=metric, **kwds)
  40. 1789
  41. -> 1790 return _parallel_pairwise(X, Y, func, n_jobs, **kwds)
  42. 1791
  43. 1792
  44.  
  45. C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in _parallel_pairwise(X, Y, func, n_jobs, **kwds)
  46. 1357
  47. 1358 if effective_n_jobs(n_jobs) == 1:
  48. -> 1359 return func(X, Y, **kwds)
  49. 1360
  50. 1361 # enforce a threading backend to prevent data communication overhead
  51.  
  52. C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in _pairwise_callable(X, Y, metric, force_all_finite, **kwds)
  53. 1401 iterator = itertools.product(range(X.shape[0]), range(Y.shape[0]))
  54. 1402 for i, j in iterator:
  55. -> 1403 out[i, j] = metric(X[i], Y[j], **kwds)
  56. 1404
  57. 1405 return out
  58.  
  59. D:\Users\psalm\AppData\Local\Temp/ipykernel_41176/1088380155.py in mydist(x, y)
  60. 3 # a distance metric function applying different weights for different features
  61. 4 def mydist(x, y):
  62. ----> 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]))
  63. 6
  64. 7 knn_regr = KNeighborsRegressor(n_neighbors=10, metric=mydist)
  65.  
  66. ValueError: operands could not be broadcast together with shapes (30,) (8,)
Advertisement
Add Comment
Please, Sign In to add comment