如何在必要的预处理后使用nltk文本分析库预测特定文本或文本组

时间:2018-04-29 13:06:30

标签: python-3.x machine-learning nlp classification logistic-regression

所有代码都在python中。我有一个名为“语料库”的python列表,其中包含总计2000的评论(+ ve和-ve评论两者)。 mycode的主要/重要部分是:

PR1 = (10 .* log10(PR)) + 30;

现在我想将一个句子预测为+ ve或-ve('1'或'0')。这句话是

clc();
close all;
clear all;

f = 2100000000;
wl = ((3 * 10^8) / f) ^ 2;
PT = 50.12;

d = 1:0.1:20;
PR = (wl ./ ((4 .* pi() .* d) .^ 2)) .* PT;

d1 = d .* 1000;
PR1 = (10 .* log10(PR)) + 30;

subplot(2,1,1);
plot(d,PR);
xlabel('x --> D (Distance in Km)');
ylabel('y --> PR (Received Power in Watts)');
title('Distance of separation between the TX/RX and the receive signal strength');
grid on;

subplot(2,1,2);
plot(d1,PR1);
xlabel('x --> D (Distance in Meter)');
ylabel('y --> PR (Received Power in dBm)');
title('Distance of separation between the TX/RX and the receive signal strength');
grid on;

我应该如何预测上述情况。(我知道CountVectorizer和TdfidfTransformer的作用是什么,但它让我对TdfidfVectorizer感到困惑)

1 个答案:

答案 0 :(得分:1)

CountVectorizerTfidfTranformer所取得的成就只能由TfidfVecorizer来实现。

回答你的问题:

sample = ["you are a nice person and have a good life"]

这是您要预测的样本数据。我在vectorizer上使用了transform方法(CountVectorizer)

Count_sample = vectorizer.transform(sample)

转换CountVectorizer后,我们必须在变换器上使用transform方法(TfidfTranformer)

Tfidf_sample = transformer.transform(Count_sample)

完成所有数据转换后,使用预测LogisticRegression

的功能
predicted = logistic_reg.predict(Tfidf_sample)