Jupyter错误-'对于给定的一段代码,内核似乎已经死亡,它将自动重新启动'

问题描述 投票:0回答:1

[每当我运行此代码时,它都会成功运行,但是当执行最后4行代码时,内核就会死掉,其中使用Apriori算法进行购物篮分析:数据集:https://archive.ics.uci.edu/ml/datasets/Online+Retail

import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
import pandas as pd
import numpy as np 
import seaborn as sns
import matplotlib.pyplot as plt
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
import mlxtend as ml
print("test1")

retail_df=pd.read_excel("Online Retail.xlsx",sheet_name="Online Retail")
retail_df.head()

rslt_df = retail_df[retail_df['Quantity'] > 5]
rslt_df=rslt_df.iloc[:10000]

rslt_df.shape
rslt_df.head()

df = rslt_df.groupby(['Quantity','Description']).size().reset_index(name='count')
df.head()

basket = df.groupby(['Quantity', 'Description'])['count'].sum().unstack().reset_index().fillna(0).set_index('Quantity')
basket

#The encoding function
def encode_units(x):
    if x <= 0:
        return 0
    if x >= 1:
        return 1
basket_sets = basket.applymap(encode_units)
basket_sets

**#THE NOTEBOOK CRASHES FOR THE BELOW 4 LINES OF CODE**

frequent_itemsets = apriori(basket_sets, min_support=0.01, use_colnames=True)
rules = association_rules(frequent_itemsets, metric="lift")
rules.sort_values('confidence', ascending = False, inplace = True)
rules.head(10)

请帮助解决此问题。我尝试了所有方法,但没有为我解决。

python machine-learning jupyter-notebook recommendation-engine apriori
1个回答
0
投票

我和你有同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.