【问题标题】:Association Rule Mining in python on Census Datapython中关于人口普查数据的关联规则挖掘
【发布时间】:2020-10-17 17:18:25
【问题描述】:

大家好,我正在做一个项目。我需要对如下图所示的人口普查数据执行关联规则挖掘。

我正在使用来自 mlxtend 库的 Apriori 算法。这是代码。

# Library Imports
import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules

# Reading the Data File
data = pd.read_csv("Census.csv")

# Reading Certain Columns of the Data File.
df = data[["Region","Residence Type","Sex","Student"]]

# Initializing the Transaction Encoder 
te = TransactionEncoder()

# Fitting the Data.
te_ary = te.fit(df).transform(df)

# Creating a Dataframe of Support and Element name
df2 = pd.DataFrame(te_ary, columns=te.columns_)

# Calling in the Apriori Algorithm.
fre = apriori(df2,min_support=0.6,use_colnames=True)

# Calling the Association Rule Function.
association_rules(fre, metric="confidence",min_threshold=0.7)

fre 变量不返回任何规则,它始终为空。有人可以帮我吗。这是请求。

【问题讨论】:

  • 你的意思是你的变量fre,它保存apriori函数调用的返回值总是空的?
  • 是的,先生,它是空的
  • 我的意思是 0.6 的 min_support 相当高...
  • 最初我使用我的计算值 0.047 @Feelx234

标签: python associations data-mining rules apriori


【解决方案1】:

我尝试了很多方法,我的一位朋友向我推荐了一种解决问题的方法。它以一种优雅的方式工作,但是是的,它也需要你的逻辑。 这是帮助我以更好的方式实现我的问题的链接here it is。 在我的解决方案中,我使用了相关参数并创建了一个篮子。

就是这样。谢谢。

【讨论】:

    猜你喜欢
    • 2015-04-29
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    相关资源
    最近更新 更多