Reputation: 23
I have a TypeError: 'numpy.ndarray' object is not callable and I have now clue what this means. I'm currently following this tutorial: https://www.youtube.com/watch?v=tNa99PG8hR8
for learing how to create a simple machine learning program using a data table provided by wikepedia which shows 3 types of tulips and the program is supposed to distinguish one from another. Right now though, it is only supposed to print the expected results for the 3 tulip types at 0, 50 and 100.
I tried to redownload python (I'm using linux) but it didn't solve the problem.
import numpy as np
from sklearn.datasets import load_iris
from sklearn import tree
iris = load_iris()
test_idx = [0, 50, 100]
# training data
train_target = np.delete(iris.target, test_idx)
train_data = np.delete(iris.data, test_idx, axis=0)
# testing data
test_target = iris.target[test_idx]
test_data = iris.data[test_idx]
clf = tree.DecisionTreeClassifier()
clf.fit(train_data, train_target())
print test_target
The program is supposed to display the target data display of the training data that will be used for testing after the model has completed it's training
Upvotes: 2
Views: 10174
Reputation: 611
Your error
TypeError: 'numpy.ndarray' object is not callable
means that you use the ()
operator on an object that does not implement it (in this case a numpy.ndarray).
A simple example would be trying to do the following:
int i = 0;
print(i())
This does not work as int
does not implement the ()
operator and is therefor not callable.
To fix your error:
The line (as @Oswald said):
clf.fit(train_data, train_target())
should look like this:
clf.fit(train_data, train_target)
Upvotes: 2
Reputation: 792
Remove the ()
from train_target
in clf.fit
, adding round braces will make it a callable
Upvotes: 4