编号20编号20编号20编号20编号20

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}")

/*
    Name:
    Copyright:
    Author: 
    Date: <DATETIME>
    Description:
*/
#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;
    // Your code here
    return 0;
}

/*
    Name:
    Copyright:
    Author: 
    Date: <DATETIME>
    Description:
*/
#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;
    }
    // Your code here
    return 0;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值