挂在视图方法中

我最近一直在通过一门课程学习 python。除非我使用 view 方法,否则一切都很顺利。有人也遇到这个问题吗?


我什至在https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html#example-plot-tipping-problem-newapi-py 中使用了示例代码。(链接已更新)


import numpy as np

import skfuzzy as fuzz

from skfuzzy import control as ctrl


quality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')

service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')

tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')


quality.automf(3)

service.automf(3)


tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])

tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])

tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])


# HERE COMES MY PROBLEM

quality['average'].view()

每当我查看查询部分时,我得到的只是一个小方框,它应该向我显示图表,但它一直在加载。任何意见是极大的赞赏。谢谢!


拉莫斯之舞
浏览 203回答 2
2回答

倚天杖

这是运行的完整示例:import matplotlib.pyplot as pltimport numpy as npimport skfuzzy as fuzzfrom skfuzzy import control as ctrlquality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')quality.automf(3)service.automf(3)tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])这是我的问题quality['average'].view()service.view()tip.view()rule1 = ctrl.Rule(quality['poor'] | service['poor'], tip['low'])rule2 = ctrl.Rule(service['average'], tip['medium'])rule3 = ctrl.Rule(service['good'] | quality['good'], tip['high'])rule1.view()tipping_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])tipping = ctrl.ControlSystemSimulation(tipping_ctrl)使用带有 Pythonic API 的 Antecedent 标签将输入传递给 ControlSystem# Note: if you like passing many inputs all at once, use .inputs(dict_of_data)tipping.input['quality'] = 6.5tipping.input['service'] = 9.8# Crunch the numberstipping.compute()print (tip)tip.view(sim=tipping)plt.show()

米脂

由于skfuzzy使用matplotlib和NetworkX底层,您可以尝试使用此代码来显示您的数字:import matplotlib.pyplot as pltimport numpy as npimport skfuzzy as fuzzfrom skfuzzy import control as ctrlquality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')quality.automf(3)service.automf(3)tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])# HERE COMES MY PROBLEMquality['average'].view()plt.show()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python