Open
Description
Simple LR
Getting ValueError: object __array__ method not producing an array
when trying to run the Matplotlib viz of simple linear regression.
import matplotlib.pyplot as plt
import cupy
# scatter actual and predicted results
plt.scatter(sY_test, sY_pred)
# label graph
plt.xlabel("Actual Prices: $Y_i$")
plt.ylabel("Predicted prices: $\hat{Y}_i$")
plt.title("Prices vs Predicted prices: $Y_i$ vs $\hat{Y}_i$")
plt.show()
type(sY_pred)==cupy.core.core.ndarray
so .to_array()
and .to_pandas()
don't work, but this can be fixed by adding .to_list()
.
Full Error Output
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-f0bf19bebebf> in <module>
2 import cupy
3 # scatter actual and predicted results
----> 4 plt.scatter(sY_test, sY_pred)
5
6 # label graph
/opt/conda-environments/rapids-stable/lib/python3.7/site-packages/matplotlib/pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, data, **kwargs)
2814 verts=verts, edgecolors=edgecolors,
2815 plotnonfinite=plotnonfinite, **({"data": data} if data is not
-> 2816 None else {}), **kwargs)
2817 sci(__ret)
2818 return __ret
/opt/conda-environments/rapids-stable/lib/python3.7/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
1563 def inner(ax, *args, data=None, **kwargs):
1564 if data is None:
-> 1565 return func(ax, *map(sanitize_sequence, args), **kwargs)
1566
1567 bound = new_sig.bind(ax, *args, **kwargs)
/opt/conda-environments/rapids-stable/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
356 f"%(removal)s. If any parameter follows {name!r}, they "
357 f"should be pass as keyword, not positionally.")
--> 358 return func(*args, **kwargs)
359
360 return wrapper
/opt/conda-environments/rapids-stable/lib/python3.7/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, **kwargs)
4375 # np.ma.ravel yields an ndarray, not a masked array,
4376 # unless its argument is a masked array.
-> 4377 x = np.ma.ravel(x)
4378 y = np.ma.ravel(y)
4379 if x.size != y.size:
/opt/conda-environments/rapids-stable/lib/python3.7/site-packages/numpy/ma/core.py in __call__(self, a, *args, **params)
6678 a, args[0] = args[0], a
6679
-> 6680 marr = asanyarray(a)
6681 method_name = self.__name__
6682 method = getattr(type(marr), method_name, None)
/opt/conda-environments/rapids-stable/lib/python3.7/site-packages/numpy/ma/core.py in asanyarray(a, dtype)
7896 if isinstance(a, MaskedArray) and (dtype is None or dtype == a.dtype):
7897 return a
-> 7898 return masked_array(a, dtype=dtype, copy=False, keep_mask=True, subok=True)
7899
7900
/opt/conda-environments/rapids-stable/lib/python3.7/site-packages/numpy/ma/core.py in __new__(cls, data, mask, dtype, copy, subok, ndmin, fill_value, keep_mask, hard_mask, shrink, order, **options)
2793 # Process data.
2794 _data = np.array(data, dtype=dtype, copy=copy,
-> 2795 order=order, subok=True, ndmin=ndmin)
2796 _baseclass = getattr(data, '_baseclass', type(_data))
2797 # Check that we're not erasing the mask.
ValueError: object __array__ method not producing an array
Multiple LR
Getting this error with the MLR plot;
TypeError: Implicit conversion to a host NumPy array via __array__ is not allowed, To explicitly construct a GPU array, consider using cupy.asarray(...)
To explicitly construct a host array, consider using .to_array()
Adding .to_array()
or .to_pandas()
makes it work.