我正在做一个电子邮件分类项目,将电子邮件分类为一个特定的类别。到目前为止,我们将有趣的数据(例如:主题和正文)以及其他信息保存到数据库中。我们成功地将术语频率-反向文档频率应用于该项目,以检索在邮件主题和正文中找到的所有术语/特征的矩阵。该矩阵的一个很小的样本输出是:
dog cat fish
doc1 0,024 0,011 0,008
doc2 0,011 0,014 0,007
doc3 0,005 0,024 0,003
doc4 0,008 0,028 0,008
doc5 0,002 0,03 0,006在现实中,这个矩阵是大得多,因为我们有大约23000条款的一组165个电子邮件。因为我们需要使用这个矩阵中的术语对电子邮件进行分类,所以23000的功能实在是太多了。这就是为什么我们实现了一个降维算法(PCA)。这是通过使用此代码(协议框架)来完成的:
// Creates the Principal Component Analysis of the given source
pca = new PrincipalComponentAnalysis(matrix, AnalysisMethod.Center);
// Compute the Principal Component Analysis
pca.Compute();
// Creates a projection of the information
double[,] components = pca.Transform(matrix, 20);
// Creates form to show components
frmRPCA frmPCA = new frmRPCA(components);
frmPCA.ShowDialog();现在我们已经对维度#进行了硬编码,但这暂时不应该是一个问题。
我一直在看协议框架中关于如何分类使用朴素贝叶斯的例子,但是我真的想不出如何将它付诸实践。主要是因为这个例子在我们处理数字的时候使用了文本,而我对分类是如何工作的还不太了解。请参阅如何实现朴素贝叶斯的示例。。
基本上,我有我的原始矩阵包含我的特征和它们的TF-以色列国防军值(见上面的样本),我想通过使用包含我的主成分分析( pca.Transform方法的输出)的矩阵来分类它们。目前,我只有两个类别,我想分类我的电子邮件(注册和提交)。我怎样才能做到这一点?另外,如果将来要添加多个类,我将如何扩展它?
示例输出应该类似于:
doc1 Registration
doc2 Registration
doc3 Registration
doc4 Submission
doc5 Submission发布于 2015-04-17 13:40:42
如果您对分类感兴趣,那么LDA (及其变体)也许更适合您的情况。事实上,PCA试图通过只查看您的数据来最小化差异。但是,如果您有关于数据的额外信息(如类标签),则有更好的方法来实现您的需要。
假设您有分类问题,下面是一个关于如何使用LDA减少特性数据数量的示例:
// Create some sample input data instances. This is the same
// data used in the Gutierrez-Osuna's example available at:
// http://research.cs.tamu.edu/prism/lectures/pr/pr_l10.pdf
double[][] inputs =
{
// Class 0
new double[] { 4, 1 },
new double[] { 2, 4 },
new double[] { 2, 3 },
new double[] { 3, 6 },
new double[] { 4, 4 },
// Class 1
new double[] { 9, 10 },
new double[] { 6, 8 },
new double[] { 9, 5 },
new double[] { 8, 7 },
new double[] { 10, 8 }
};
int[] output =
{
0, 0, 0, 0, 0, // The first five are from class 0
1, 1, 1, 1, 1 // The last five are from class 1
};
// Then, we will create a LDA for the given instances.
var lda = new LinearDiscriminantAnalysis(inputs, output);
lda.Compute(); // Compute the analysis
// Now we can project the data into LDA space:
double[][] projection = lda.Transform(inputs);如果您想将问题从二维降到一维,可以使用:
double[][] reduced_data = lda.Transform(inputs, 1);结果将是一个10x1矩阵。它将包含对执行分类仍然有用的数据的较低维表示。因此,您将能够使用reduced_data代替使用原始数据来学习分类器。
此外,LDA对象附带了一个简单的最小距离分类器,您可以使用它来分类实例。例如,可以使用以下方法对数据集进行分类:
int[] results = lda.Classify(inputs);但是,没有什么可以阻止您使用您可能喜欢的任何其他分类器(比如朴素贝叶斯)。例如,为了使用朴素的Bayes,可以使用
// Create a new normal distribution Naive Bayes classifier for
// a classification problem with 1 feature and the two classes
var nb = new NaiveBayes.Normal(classes: 2, inputs: 1);
// Compute the Naive Bayes model
nb.Estimate(reduced_data, output);
// Now, if we would like to classify the first instance
// in our dataset, we would use
int result = nb.Compute(lda.Transform(input[0]));https://stackoverflow.com/questions/29696565
复制相似问题