построение трехмерного графика в SVM и получение этой ошибки памяти в Colab - PullRequest
0 голосов
/ 02 августа 2020
    import numpy as np
import plotly.graph_objects as go

x = np.linspace(-1,1, 50)
y = np.linspace(-1,3, 100)
x, y = np.meshgrid(x,y)

z = x**3-3*y*x+1  # the surface eqn

fig = go.Figure()
fig.add_surface(x=x, y=y, z=z, colorscale='Reds_r', colorbar_thickness=25, colorbar_len=0.75);

X = np.linspace(-1,1, 6)
Y = np.linspace(-1, 3, 12)
#Define the first family of coordinate lines
X, Y = np.meshgrid(X_train,y_train)
Z = X**3-3*Y*X+1
line_marker = dict(color='#101010', width=4)
for xx, yy, zz in zip(X, Y, Z+0.03):
    fig.add_scatter3d(x=xx, y=yy, z=zz, mode='lines', line=line_marker, name='')
#Define the second family of coordinate lines
Y, X = np.meshgrid(Y, X)
Z = X**3-3*Y*X+1
line_marker = dict(color='#101010', width=4)
for xx, yy, zz in zip(X, Y, Z+0.03):
    fig.add_scatter3d(x=xx, y=yy, z=zz, mode='lines', line=line_marker, name='')    
fig.update_layout(width=700, height=700, showlegend=False)

Я пытаюсь построить трехмерный график с линиями опорных векторов, но сталкиваюсь с этой ошибкой. Я не понимаю, почему это происходит. Есть ли какие-то ограничения в Google Colaboratory? Кроме того, он показывает, что массив с формой (20800000, 20800000) не может быть отображен, но в моем наборе данных всего 500 строк и 13 столбцов.

---------------------------------------------------------------------------

MemoryError                               Traceback (most recent call last)

<ipython-input-10-e6f0a172ab17> in <module>()
     20     fig.add_scatter3d(x=xx, y=yy, z=zz, mode='lines', line=line_marker, name='')
     21 #Define the second family of coordinate lines
---> 22 Y, X = np.meshgrid(Y, X)
     23 Z = X**3-3*Y*X+1
     24 line_marker = dict(color='#101010', width=4)

<__array_function__ internals> in meshgrid(*args, **kwargs)

1 frames

/usr/local/lib/python3.6/dist-packages/numpy/lib/function_base.py in <listcomp>(.0)
   4207 
   4208     if copy_:
-> 4209         output = [x.copy() for x in output]
   4210 
   4211     return output

MemoryError: Unable to allocate 3.07 PiB for an array with shape (20800000, 20800000) and data type float64
...