import csv
from efficient_apriori import apriori
from time import time
from collections import Counter
# 初始化数据列表
data = []
# 尝试读取CSV文件
try:
with open('mushroom.dat', 'r', encoding='utf8') as f:
reader = csv.reader(f)
for row in reader:
data.append(row)
except Exception as e:
print(f"Error reading the CSV file: {e}")
# 检查读取的数据
print("Data loaded from CSV:")
for i, row in enumerate(data[:5]): # 打印前5行数据
print(f"Row {i}: {row}")
# 转换参数格式
transactions = [tuple(row) for row in data]
# 检查转换后的事务数据
print("Transactions:")
for i, transaction in enumerate(transactions[:5]): # 打印前5个事务
print(f"Transaction {i}: {transaction}")
# 记录开始时间
start_time = time()
# 使用Apriori算法找到频繁项集
min_support = 0.50 # 降低最小支持度
min_confidence = 0.2 # 降低最小置信度
itemsets, rules = apriori(transactions, min_support=min_support, min_confidence=min_confidence)
# 记录结束时间
end_time = time()
elapsed_time = end_time - start_time
# 统计频繁项集的总数
total_itemsets = sum(len(itemset) for itemset in itemsets.values())
# 打印结果
print('频繁项集:', itemsets)
print('频繁项集总数:', total_itemsets)
print('关联规则:', rules)
print('运行时间:', elapsed_time, '秒')
# # 打印每个项的频率
# item_counter = Counter()
# for transaction in transactions:
# item_counter.update(transaction)
#
# print("Item frequencies:")
# for item, count in item_counter.items():
# print(f"{item}: {count}")
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int a,b,c,d;
cin >> a >> b >> c >> d;
cout<< c <<" "<< d << endl;
return 0;
}
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n != 0){
int day = n;
int sumGood = 0;
int number = 1,time = 1;
while (n > 0){
if (number == time){
sumGood += number;
number++;
time = 1;
}else{
sumGood += number;
time++;
}
n--;
}
cout << day <<" "<< sumGood <<endl;
cin >> n;
}
return 0;
}