c# - 查找项目列表中出现频率最高的组合
问题描述
在我的 asp.net c# 应用程序中,我有以下项目组合的出现列表。我想列出最常出现的组合。
- 项目1
- 项目 1、项目 2
- 第 3 项
- 项目 1、项目 3、项目 2
- 第 3 项,第 1 项
- 第 2 项,第 1 项
根据上面的例子,我应该得到下面的输出。
最常出现的组合是;
- 项目 1 和项目 2 - 出现次数为 3(#2、#4 和 #6)
- Item1 & Item3 - 出现次数为 2 (#4 & #5)
我的结构如下。
public class MyList
{
public List<MyItem> MyItems { get; set; }
}
public class MyItem
{
public string ItemName { get; set; }
}
解决方案
Out of the top of my head i would map all possible combinations using a hash where ab
is the same as ba
(or you could order your items alphabetically for example and then hash them) and then just count occurrences of the hashes...
推荐阅读
- r - 在 R 的 sqldf 中使用 UPDATE 语句
- apache-spark - 如果对中间结果应用两个不同的转换,火花是否会重新计算中间结果?
- wpf - DataContext Set 后的 DataTemplate 选择器
- r - 如何在数据框中的两列上使用 seq 函数?
- javascript - 使用javascript向html表添加新列
- reactjs - 如何修复 npm start “无法确定原生 SDK 版本”错误?
- python-3.x - 基于来自不同数据框的条件的新数据框列
- c# - 如何使用 ASP.NET Core 3.1 调整 IFormFile 的大小
- python - 在运行时在 Lambda 中加载 Python 包
- java - 将列表中最喜欢的项目存储到android中的SharedPreferences中?