Uknown TypeError: 'numpy.ndarray' object is not callable












1















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










share|improve this question



























    1















    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










    share|improve this question

























      1












      1








      1








      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










      share|improve this question














      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







      python scikit-learn






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 31 '18 at 3:43









      WilliamWilliam

      82




      82
























          2 Answers
          2






          active

          oldest

          votes


















          2














          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)





          share|improve this answer


























          • Thank you very much! It fixed the problem!

            – William
            Dec 31 '18 at 4:22



















          4














          Remove the () from train_target in clf.fit, adding round braces will make it a callable






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983389%2fuknown-typeerror-numpy-ndarray-object-is-not-callable%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            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)





            share|improve this answer


























            • Thank you very much! It fixed the problem!

              – William
              Dec 31 '18 at 4:22
















            2














            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)





            share|improve this answer


























            • Thank you very much! It fixed the problem!

              – William
              Dec 31 '18 at 4:22














            2












            2








            2







            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)





            share|improve this answer















            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)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 31 '18 at 7:14

























            answered Dec 31 '18 at 3:59









            KanjiuKanjiu

            42110




            42110













            • Thank you very much! It fixed the problem!

              – William
              Dec 31 '18 at 4:22



















            • Thank you very much! It fixed the problem!

              – William
              Dec 31 '18 at 4:22

















            Thank you very much! It fixed the problem!

            – William
            Dec 31 '18 at 4:22





            Thank you very much! It fixed the problem!

            – William
            Dec 31 '18 at 4:22













            4














            Remove the () from train_target in clf.fit, adding round braces will make it a callable






            share|improve this answer




























              4














              Remove the () from train_target in clf.fit, adding round braces will make it a callable






              share|improve this answer


























                4












                4








                4







                Remove the () from train_target in clf.fit, adding round braces will make it a callable






                share|improve this answer













                Remove the () from train_target in clf.fit, adding round braces will make it a callable







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 31 '18 at 3:53









                OswaldOswald

                623917




                623917






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983389%2fuknown-typeerror-numpy-ndarray-object-is-not-callable%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas