python - TypeError:“numpy.ndarray”和“str”错误的实例之间不支持“>”
问题描述
#im 正在处理 covid 19 数据集的任务并使用 apriori 算法对其进行分析,但是我一直遇到问题并且我在编程方面非常糟糕 #i 首先导入了这些库
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
!pip install efficient_apriori
#加载数据
from google.colab import files
uploaded = files.upload()
#读取文件并显示
df = pd.read_csv('covid_dataset.csv')
df
#did this to turn the dataframe to a tuple
records = df.to_records(index=False)
result = list(records)
#这里有问题
from efficient_apriori import apriori
min_support = 7/len(result)
min_confidence = 0
itemsets, rules = apriori(result, min_support=min_support, min_confidence=min_confidence)
#这里是错误
TypeError Traceback (most recent call last)
<ipython-input-17-e29e44a028ef> in <module>()
6 # For now set min_confidence = 0 to obtain all the rules
7 min_confidence = 0
----> 8 itemsets, rules = apriori(result, min_support=min_support, min_confidence=min_confidence)
1 frames
/usr/local/lib/python3.7/dist-packages/efficient_apriori/itemsets.py in itemsets_from_transactions(transactions, min_support, max_length, verbosity, output_transaction_ids)
312 # Retrieve the itemsets of the previous size, i.e. of size k - 1
313 # They must be sorted to maintain the invariant when joining/pruning
--> 314 itemsets_list = sorted(item for item in large_itemsets[k - 1].keys())
315
316 # Gen candidates of length k + 1 by joining, prune, and copy as set
TypeError: '>' not supported between instances of 'numpy.ndarray' and 'str'
解决方案
推荐阅读
- windows - 使用powershell将文件排序到目录中
- swift - Swift - Algolia - InstantSearch 的排序结果
- python - 如何使用 python re 库拆分字符串并保留分隔符?
- r - 如何在 r 中的 data.table 中按链排序?
- oracle - 如何迭代sqlplus中的位置脚本参数?
- excel - 解决SVN冲突-excel文件
- json - 需要针对 Json Schema 验证 Json 数据
- ant - 我如何使用蚂蚁
在 Windchill 上执行命令? - android - 尝试从firebase获取数据时出现空指针异常
- mailgun - 从 Mailgun 中发送的电子邮件中获取重写的链接