An example of Python

Online IDE: 在线运行Python(3.8.1) - JSON中文网

#测试于https://www.json.cn/run/python3/
#编写python程序:
#1. 编写函数,接收任意多个实数,返回一个元组,其中第一个元素为所有参数的平均值,其他元素为所有参数中大于平均值的实数。
def receive(lst):
    li=[]
    avg=sum(lst)/len(lst)
    li.append(avg)
    for i in lst:
        if i>avg:
            li.append(i)
    return li
lst=list(map(int,input().split(" ")))#接收多个数据
tp=tuple(receive(lst))
print(tp)
#需要输入,如2 0 2 4
#2.编写一个实现冒泡排序的函数,并用该函数对列表中的元素按升序排列。
def bubble(num_list):
    for i in range(len(num_list)):
        for j in range(i):
            if num_list[j] > num_list[i]:
                num_list[j], num_list[i] = num_list[i], num_list[j]
    return num_list
 
list = [2,4,7,87,32,90,11,0,577]
print(list)
print(bubble(list))
#无需输入
#3.编写一个接收年月日作为输入参数的函数,输出参数所指定的日期是一年中的第几天。例如每年的1月1日都是本年度的第1天, 2023年的3月1日是本年的第60天,而2024年(闰年)的3月1日则是本年的第61天。
time = input('请输入日期 YYYY-MM-DD:')
date = time.split('-')
year = int(date[0])
month = int(date[1])
day = int(date[2])
li = [31,28,31,30,31,30,31,31,30,31,30,31]
num = 0
if ((year % 4 ==0) and (year % 100 != 0) or (year % 400 == 0)):
      li[1] = 29
for i in range(12):
      if month > i + 1:
          num += li[i]
      else:
          num += day
          break
print('这一天是%d年的第%d天' %(year,num))
#需要输入,如2024-6-19

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Certainly! Here's an example of fuzzy association rule mining using the Python library scikit-fuzzy: ```python import numpy as np import pandas as pd import skfuzzy as fuzz from sklearn.preprocessing import LabelEncoder # Load the dataset dataset = pd.read_csv('your_dataset.csv') # Preprocess the dataset label_encoder = LabelEncoder() dataset['Item'] = label_encoder.fit_transform(dataset['Item']) # Fuzzify the dataset fuzzy_dataset = fuzz.interp_membership(dataset['Item'], np.arange(len(dataset['Item'])), dataset['Support'], np.max) # Generate frequent itemsets frequent_itemsets = fuzz.frequent_itemsets(fuzzy_dataset, min_support=0.3, min_confidence=0.6) # Generate fuzzy association rules fuzzy_rules = fuzz.generate_association_rules(frequent_itemsets, min_confidence=0.6) # Print the fuzzy association rules for rule in fuzzy_rules: print(rule) ``` In this example, we assume that you have a dataset stored in a CSV file. The dataset contains two columns: 'Item' and 'Support'. 'Item' represents the items or products, and 'Support' represents their support values. First, we preprocess the dataset by encoding the categorical 'Item' column using LabelEncoder. Next, we fuzzify the dataset using `interp_membership` function, which assigns degrees of membership to each item based on their support values. Then, we generate frequent itemsets using the `frequent_itemsets` function. We specify the minimum support threshold (min_support) to determine which itemsets are frequent. Finally, we generate fuzzy association rules using the `generate_association_rules` function. We specify the minimum confidence threshold (min_confidence) to filter out weak rules. The generated fuzzy association rules are then printed out for further analysis. Please note that you need to adjust the parameters and adapt this code to your specific dataset and requirements. Also, ensure that you have the scikit-fuzzy library installed (`pip install scikit-fuzzy`) before running this code.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值