modeles terminés, pas testés

This commit is contained in:
François Pelletier 2019-11-01 00:14:55 -04:00
parent b9c99e321e
commit 196b0d9649
2 changed files with 40 additions and 7 deletions

View file

@ -13,9 +13,6 @@ from scipy.sparse import csr_matrix, hstack
# nltk.download('sentiwordnet')
# from sklearn.naive_bayes import MultinomialNB
# from sklearn.linear_model import LogisticRegression
train_pos_reviews_fn = "./data/train-positive-t1.txt"
train_neg_reviews_fn = "./data/train-negative-t1.txt"
test_pos_reviews_fn = "./data/test-pos-t1.txt"
@ -160,3 +157,33 @@ if __name__ == '__main__':
v_final_test.append(v_select_final_test)
# Scoring des modèles
modeles_nb = []
scores_nb = []
modeles_reg = []
scores_reg = []
for norm_method in range(0,2):
modeles_select_vector_nb = []
scores_select_vector_nb = []
modeles_select_vector_reg = []
scores_select_vector_reg = []
for select_method in range(0,3):
modeles_vector_nb = []
scores_vector_nb = []
modeles_vector_reg = []
scores_vector_reg = []
for vector_method in range(0,3):
modele_nb = sfun.train_naive_model(v_final_train[norm_method][select_method][vector_method],train_dataset_response)
score_nb = modele_nb.predict(v_final_test[norm_method][select_method][vector_method])
modele_reg = sfun.train_regression_model(v_final_train[norm_method][select_method][vector_method],train_dataset_response)
score_reg = modele_reg.predict(v_final_test[norm_method][select_method][vector_method])
modeles_vector_reg.append(modele_reg)
scores_vector_reg.append(score_reg)
modeles_select_vector_nb.append(modeles_vector_nb)
scores_select_vector_nb.append(scores_vector_nb)
modeles_select_vector_reg.append(modeles_vector_reg)
scores_select_vector_reg.append(scores_vector_reg)
modeles_nb.append(modeles_select_vector_nb)
scores_nb.append(scores_select_vector_nb)
modeles_reg.append(modeles_select_vector_reg)
scores_reg.append(scores_select_vector_reg)

View file

@ -13,6 +13,8 @@ from collections import defaultdict
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
from nltk.corpus import wordnet as wn
from nltk.corpus import sentiwordnet as swn
from sklearn.naive_bayes import MultinomialNB
from sklearn.linear_model import LogisticRegression
# Normalisation
@ -182,9 +184,13 @@ def attribute_polarity_count(norm_reviews):
# Training
def train_naive_model(reviews):
return 0
def train_naive_model(reviews_vectors,reviews_response):
mnb = MultinomialNB()
mnb.fit(reviews_vectors,reviews_response)
return mnb
def train_regression_model(reviews):
return 0
def train_regression_model(reviews_vectors,reviews_response):
lrm = LogisticRegression(solver='liblinear', max_iter=1000)
lrm.fit(reviews_vectors,reviews_response)
return lrm