Problems with accuracy.score sklearn I am learning python and trying myself out at mashine learning. I am reproducing a super simple example - based on the infamous iris dataset. Here it goes: 

from sklearn import datasets
iris = datasets.load_iris()

X = iris.data
y = iris.target

from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .5)

from sklearn import tree
nordan_tree = tree.DecisionTreeClassifier()

nordan_tree.fit(X_train, y_train)

from sklearn.metrics import accuracy_score 


I get the following error message: 

Traceback (most recent call last):
  File "tree3.py", line 17, in &lt;module&gt;
    print(accuracy_score(y_test, predictions))
NameError: name 'predictions' is not defined


I don't get it. As far as I understand, predictions is the vector containing all the predictions produced with  DecisionTreeClassifier? What am I doing wrong?
You have not defined the variable predictions anywhere. You will need to get them from your classifier somehow. You have fit your nordan_tree on your training data, now you can use the fitted nordan_tree to generate the predictions, for example like this:

predictions = nordan_tree.predict(X_test)


Then your line of:

print(accuracy_score(y_test, predictions))


should work.