尝试进行收视率预测

时间:2019-05-30 10:44:27

标签: python prediction

我正在使用以下功能:

def prediction_rate(model_name):
  print("welcome ! \nplease enter the first text ! : ")
  ID1 = input()
  print("please enter the second text ! : ")
  rev = input()
  comment1=encoding(ID1)
  comment2=encoding(rev)
  y=model_name.predict([commentaire1,commentaire2])
  c = np.argmax(y)
  Switcher={
    0:'Satisfaction Percentage : {:.1f}'.format(
   (y[0][c]/5)*100)+ ' %'}

print(Switcher.get(c))

在此代码中,comment1和comment2是使用多输入CNN模型进行预测的输入。 Comment1和comment2由以下问题预处理:

def encoding(text):
  text = clean_str(text)
  text = preprocessing(text)
  vocabulary,vocabulary_inv = build_vocab(text)
  text = pad_sentences(text,100)
  x_users = np.array([vocabulary[word] for word in text])
  x_test = sequence.pad_sequences(x_users, maxlen=100)
  return x_test

运行prediction_rate(model_name)后出现此错误:

 File "<ipython-input-26-8859e8cf819b>", line 1, in <module>
 prediction_rate(model_name)

 File "<ipython-input-25-e74c3c5bf609>", line 6, in prediction_rate
comment1=encoding(ID1)

 File "<ipython-input-24-73d50eec77a1>", line 3, in encoding
text = preprocessing(text)

 File "C:\Users\Amin Chaari\Apothek\data_clean.py", line 159, in preprocessing
 words=stems, lemmas(words)

TypeError: 'list' object is not callable

预处理功能:

def preprocessing(words):
 words = remove_non_ascii(words)
 words = to_lowercase(words)
 words = remove_punctuation(words)

 words = remove_stopwords(words)
 words  =stem_words(words)
 words=lemmatize_verbs(words)
 words= stem_and_lemmatize(words)
 words=stems, lemmas(words)
 return words

然后:

def stem_and_lemmatize(words):
 stems = stem_words(words)
 lemmas = lemmatize_verbs(words)
 return stems, lemmas

stems, lemmas = stem_and_lemmatize(words)

0 个答案:

没有答案