1

我目前正在做一个需要使用FP-Growth算法的项目。我知道Weka是一个方便的工具。但是,我使用 C# 进行编码(由于我需要一些其他库)。所以,我转换weka.jarweka.dll使用IKVM.NET. 以下是我编写的代码片段:

 FPGrowth FPMiner = new FPGrowth();
 FPMiner.buildAssociations(dataset);
 AssociationRules rules = FPMiner.getAssociationRules();
 List<AssociationRule> rule = rules.getRules();

这给了我一个错误:

无法将类型“java.util.List”隐式转换为“System.Collections.Generic.List”。存在显式转换(您是否缺少演员表?)

所以,我在最后一行添加了一个演员表:

List<AssociationRule> rule = (System.Collections.Generic.List<AssociationRule>)rules.getRules();

错误消失了,但是当我运行代码时出现异常,说:

System.InvalidCastException 未处理 Message=Unable to cast object of type 'java.util.ArrayList' to type System.Collections.Generic.List`1[weka.associations.AssociationRule]'。源=WindowsFormsApplication1

堆栈跟踪如下:

  StackTrace:
       at DetectGroup.Form1.GenerateARFF() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 279
       at DetectGroup.Form1.findNearestNeighbours() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 236
       at DetectGroup.Form1.findSelectedTraj() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 165
       at DetectGroup.Form1.button2_Click(Object sender, EventArgs e) in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 404
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at DetectGroup.Program.Main() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()   InnerException:

我不知道现在该做什么。我试过搜索东西,但还没有找到解决方案。我知道该错误是因为在我尝试将其getRules()用作. 我能做些什么来避免它?任何帮助都会很棒!java.util.ListSystem.Collections.Generic.List

此外,C# 中是否有任何数据挖掘库(如 Weka)?

谢谢!

4

1 回答 1

0

我正在回答我自己的问题。我使用此链接来解决我面临的问题。谢谢@SecretSquirrel(见评论)和@Jon Iles(见我链接的答案)。

于 2013-08-29T18:15:00.903 回答