2
j=pd.read_excel('train1.xls', 'sheet1', na_values=['NA', '?'],header=None)
j.columns=['News','Sentiment']
train = [(j.News,j.Sentiment)]
cl = DecisionTreeClassifier(train)

Getting TypeError: basic_extractor() takes exactly 2 arguments (1 given) But while using the following code I am not getting any error:-

train = [('I love this sandwich.', 'pos'),
    ('This is an amazing place!', 'pos'),
    ('I feel very good about these beers.', 'pos'),
    ('I do not like this restaurant', 'neg'),
    ('I am tired of this stuff.', 'neg'),
    ("I can't deal with this", 'neg'),
    ("My boss is horrible.", "neg")
 ]
cl = DecisionTreeClassifier(train)

This time it is working. Do you know the what's the problem in the first case?

3
  • 1
    Please make some minimal effort to debug the issue yourself. Commented Jun 28, 2017 at 12:51
  • 1
    train = j[["News","Sentiment"]] Commented Jun 28, 2017 at 12:53
  • You should print the train and inspect very closely whats the difference between the two. Commented Jun 28, 2017 at 16:24

1 Answer 1

2

I think you need zip:

#for python 2 omit list
train = list(zip(j.News,j.Sentiment))

Sample:

a = train = [('I love this sandwich.', 'pos'),
    ('This is an amazing place!', 'pos'),
    ('I feel very good about these beers.', 'pos'),
    ('I do not like this restaurant', 'neg'),
    ('I am tired of this stuff.', 'neg'),
    ("I can't deal with this", 'neg'),
    ("My boss is horrible.", "neg")
 ]
j = pd.DataFrame(a, columns=['News','Sentiment'])
print (j)
                                  News Sentiment
0                I love this sandwich.       pos
1            This is an amazing place!       pos
2  I feel very good about these beers.       pos
3        I do not like this restaurant       neg
4            I am tired of this stuff.       neg
5               I can't deal with this       neg
6                 My boss is horrible.       neg

train = list(zip(j.News,j.Sentiment))
print (train)
[('I love this sandwich.', 'pos'), ('This is an amazing place!', 'pos'), ('I feel very good about these beers.', 'pos'), ('I do not like this restaurant', 'neg'), ('I am tired of this stuff.', 'neg'), ("I can't deal with this", 'neg'), ('My boss is horrible.', 'neg')]
Sign up to request clarification or add additional context in comments.

8 Comments

While using your code, I am getting a tuple type list and when I am calling this I am getting TypeError: basic_extractor() takes exactly 2 arguments (1 given). I don't think their is any problem with my data.
I dont understand, in your question last paragraph works? train = [('I love this sandwich.', 'pos'), ('This is an amazing place!', 'pos'), ('I feel very good about these beers.', 'pos'), ('I do not like this restaurant', 'neg'), ('I am tired of this stuff.', 'neg'), ("I can't deal with this", 'neg'), ("My boss is horrible.", "neg") ] cl = DecisionTreeClassifier(train) ?
Or do you need cl = DecisionTreeClassifier(j[["News","Sentiment"]]) ?
Yes, even I don't know what's wrong with it. I am trying to use this api with my training data.
OK, give me some time, I try test it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.