Kaepxer
Kaepxer

Reputation: 380

'tuple' object has no attribute 'data'

I'm practicing about classifications. I could see iris has both attribute when I printed it. But I still getting same error.

from sklearn import datasets
from sklearn.metrics import classification_report
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split

iris = datasets.load_iris(),

X = iris.data
y = iris.target

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

nb_classifier = GaussianNB()

nb_classifier.fit(X_train, y_train)

y_pred = nb_classifier.predict(X_test)
print(classification_report(y_test, y_pred))

Error

Upvotes: 0

Views: 895

Answers (1)

Yevhen Kuzmovych
Yevhen Kuzmovych

Reputation: 12130

Remove the , at the end of

iris = datasets.load_iris(),

Otherwise iris becomes a tuple with one element. Your line is identical to:

iris = (datasets.load_iris(),)

Upvotes: 3

Related Questions