-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtarefa_5.py
27 lines (21 loc) · 951 Bytes
/
tarefa_5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Ola vamos criar
import pickle
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
from sklearn.pipeline import Pipeline
from sklearn.svm import LinearSVC
from sklearn.metrics import classification_report
from sklearn.tree import DecisionTreeClassifier
with open('itens.pkl', 'rb') as f_in:
items = pickle.load(f_in)
print(f"Carregamos um conjunto com {len(items)} itens")
metade = int(len(items)/2)
X_test, y_test = zip(*items[:metade]) # Vamos separar metade para teste
X_train, y_train = zip(*items[metade:]) # O restante vai ser usado para treino
# TODO Mudar para o LinearSVC
classifier = DecisionTreeClassifier(class_weight='balanced')
# TODO usar um Pipeline com CountVectorizer e TfidfTransformer
classifier.fit(X_train, y_train)
# Testes
predicted_labels = classifier.predict(X_test)
target_names = ['pessoa', 'empresa']
print(classification_report(y_test, predicted_labels, target_names=target_names))