我已编写此代码以生成两个项目集。
我正在编写list<list<>>
列表列表以生成两个项集,并希望优化代码以生成长度为k的项集。
using System.Data.OleDb;
using Microsoft.AnalysisServices.AdomdClient;
namespace HW3
{
class Program
{
private static int Min_support = 360;
private static List<String> itemSet = new List<string>();
private static List<List<String>> C_itemSet = new List<List<string>>();
static void Main(string[] args)
{
List_Movies();
//for (int k = 1; k < 3; k++)
//{ }
C_itemSet = Geneate_Sets(itemSet);
for (int i = 0; i < C_itemSet.Count; i++)
{
for (int j = 0; j < C_itemSet[i].Count; j++)
{
Console.Write(C_itemSet.ElementAt(i).ElementAt(j));
}
Console.WriteLine();
}
Console.ReadKey();
}
private static void List_Movies()
{
string connectionString = @"Provider=SQLOLEDB;Server=.;AttachDbFilename=D:\DBs\MovieClick.mdf;Database=dbname; Trusted_Connection=Yes;";
OleDbConnection myConn = new OleDbConnection(connectionString);
myConn.Open();
string str = "select Movie,COUNT(Movie) from Movies group by Movie HAVING COUNT(MOVIE) > "+Min_support;
OleDbCommand myComm = new OleDbCommand(str, myConn);
OleDbDataReader DR = myComm.ExecuteReader();
while (DR.Read())
{
if (DR[0] != null)
itemSet.Add(DR[0].ToString()); // Movie name
}
myConn.Close();
}
private static List<List<String>> Geneate_Sets(List<String> fSet )
{
List<List<String>> finalSet= new List<List<string>>();
for (int i = 0; i < fSet.Count; i++)
{
for (int j = i+1; j < fSet.Count; j++)
{
if (!fSet[i].Equals(fSet[j]))
{
List<string> temp = new List<string>();
temp.Add(fSet[i]);
temp.Add(fSet[j]);
finalSet.Add(temp);
}
}
}
return finalSet;
}
答案 0 :(得分:0)
除非您的数据确实非常庞大,否则我建议您将其加载到已经正确实施Apriori的良好库中。
因为根据您的代码判断,您实际上远非Apriori实现远,尤其是实际表现良好的实施,抱歉。就是这样,你似乎没有APRIORI的任何东西。不要指望我们为你编写算法。