1 year ago
#372679
EM MOOGG
seaborn ValueError: could not broadcast input array from shape (XX,1) into shape (XX,)
from sklearn.datasets import load_wine
import pandas as pd
import numpy as np
wine = load_wine()
wine_data = wine.data
wine_target = wine.target
df = pd.DataFrame(data=wine_data, columns = [wine.feature_names])
df['target']=wine.target
print(df)
from sklearn.model_selection import train_test_split
train_data, test_data, train_target, test_target = train_test_split(wine_data, wine_target, test_size = 0.3, random_state = 42)
from sklearn.neighbors import KNeighborsClassifier
kn = KNeighborsClassifier(n_neighbors = 7)
kn.fit(train_data, train_target)
print("\n\nTrain Eval : ", kn.score(train_data, train_target))
print("Test Eval : ", kn.score(test_data, test_target),'\n\n')
train_view = pd.DataFrame(data=train_data, columns = [wine.feature_names])
train_view['target']=train_target
print(train_view)
import seaborn as sns
sns.set_style()
sns.pairplot(train_view, hue = 'target')
In colab(google site), I have an error about displaying pairplot about my dataframe. but I don't understand this error.
[Error : ValueError: could not broadcast input array from shape (124,1) into shape (124,)][1]
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/seaborn/_core.py in categorical_order(vector, order)
1478 try:
-> 1479 order = vector.cat.categories
1480 except (TypeError, AttributeError):
11 frames
AttributeError: 'DataFrame' object has no attribute 'cat'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
AttributeError: 'DataFrame' object has no attribute 'unique'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/dtypes/cast.py in construct_1d_object_array_from_listlike(values)
1988 # making a 1D array that contains list-likes is a bit tricky:
1989 result = np.empty(len(values), dtype="object")
-> 1990 result[:] = values
1991 return result
1992
ValueError: could not broadcast input array from shape (124,1) into shape (124,)
python
seaborn
knn
0 Answers
Your Answer