Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erro ao tentar colorir o gráfico

Assim que coloquei o parametro hue=modelo.labels_ ocorreu o seguinte erro.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-56-8d10ac0b987f> in <module>
      7 sns.scatterplot(x=visualizacao[:,0],
      8                y=visualizacao[:,1],
----> 9                hue=modelo.labels_)

~/anaconda3/lib/python3.7/site-packages/seaborn/relational.py in scatterplot(x, y, hue, style, size, data, palette, hue_order, hue_norm, sizes, size_order, size_norm, markers, style_order, x_bins, y_bins, units, estimator, ci, n_boot, alpha, x_jitter, y_jitter, legend, ax, **kwargs)
   1333         x_bins=x_bins, y_bins=y_bins,
   1334         estimator=estimator, ci=ci, n_boot=n_boot,
-> 1335         alpha=alpha, x_jitter=x_jitter, y_jitter=y_jitter, legend=legend,
   1336     )
   1337 

~/anaconda3/lib/python3.7/site-packages/seaborn/relational.py in __init__(self, x, y, hue, size, style, data, palette, hue_order, hue_norm, sizes, size_order, size_norm, dashes, markers, style_order, x_bins, y_bins, units, estimator, ci, n_boot, alpha, x_jitter, y_jitter, legend)
    850 
    851         plot_data = self.establish_variables(
--> 852             x, y, hue, size, style, units, data
    853         )
    854 

~/anaconda3/lib/python3.7/site-packages/seaborn/relational.py in establish_variables(self, x, y, hue, size, style, units, data)
    155                 units=units
    156             )
--> 157             plot_data = pd.DataFrame(plot_data)
    158 
    159         # Option 3:

~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    390                                  dtype=dtype, copy=copy)
    391         elif isinstance(data, dict):
--> 392             mgr = init_dict(data, index, columns, dtype=dtype)
    393         elif isinstance(data, ma.MaskedArray):
    394             import numpy.ma.mrecords as mrecords

~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in init_dict(data, index, columns, dtype)
    210         arrays = [data[k] for k in keys]
    211 
--> 212     return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
    213 
    214 

~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype)
     49     # figure out the index, if necessary
     50     if index is None:
---> 51         index = extract_index(arrays)
     52     else:
     53         index = ensure_index(index)

~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in extract_index(data)
    315             lengths = list(set(raw_lengths))
    316             if len(lengths) > 1:
--> 317                 raise ValueError('arrays must all be same length')
    318 
    319             if have_dicts:

ValueError: arrays must all be same length

Parece ser uma diferença no tamanho de algum array comparado com outro. Como resolver?

1 resposta
solução!

Opa, agora funcionou! Provavelmente eu executei alguma célula fora de ordem e o DataFrame deve ter ficado com valores errados. Limpei tudo e executei do zero. Funcionou 100%