Reputation: 561
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?
Upvotes: 2
Views: 64
Reputation: 862641
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')]
Upvotes: 2