import numpy as np import skfuzzy as fuzz from skfuzzy import control as ctrl # 商品类别变量 category = ctrl.Antecedent(np.arange(0, 11, 1), 'category') # 用户偏好变量 preference = ctrl.Antecedent(np.arange(0, 11, 1), 'preference') # 推荐度变量 recommendation = ctrl.Consequent(np.arange(0, 11, 1), 'recommendation') # 定义范围和模糊集 category.automf(3) preference.automf(3) recommendation.automf(3) # 规则 rule1 = ctrl.Rule(category['poor'] | preference['poor'], recommendation['poor']) rule2 = ctrl.Rule(category['average'] & preference['average'], recommendation['average']) rule3 = ctrl.Rule(category['good'] | preference['good'], recommendation['good']) rule4 = ctrl.Rule(category['good'] & preference['poor'], recommendation['average']) rule5 = ctrl.Rule(category['poor'] & preference['good'], recommendation['average']) recommendation_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5]) recommendation_simulation = ctrl.ControlSystemSimulation(recommendation_ctrl) # 输入商品类别和用户偏好 recommendation_simulation.input['category'] = 8 recommendation_simulation.input['preference'] = 5 # 推荐度计算 recommendation_simulation.compute() # 输出推荐度 print("Recommendation: ", recommendation_simulation.output['recommendation']) # 可视化 category.view() preference.view() recommendation.view()为什么可视化窗口无法稳定存在
时间: 2024-01-23 09:03:19 浏览: 143
import numpy as np import matplotlib.pyplot as plt import math
这可能是由于您的可视化窗口没有被阻塞,导致它无法稳定存在。您可以在代码的末尾添加如下代码:
```python
import matplotlib.pyplot as plt
plt.show()
```
这将展示出所有的图形,并且阻塞程序,直到所有的图形窗口都被关闭。这样可以确保您的可视化窗口稳定存在,直到您手动关闭它们。
阅读全文