为了账号安全,请及时绑定邮箱和手机立即绑定

挂在视图方法中

挂在视图方法中

拉莫斯之舞 2021-11-09 18:30:09
我最近一直在通过一门课程学习 python。除非我使用 view 方法,否则一切都很顺利。有人也遇到这个问题吗?我什至在https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html#example-plot-tipping-problem-newapi-py 中使用了示例代码。(链接已更新)import 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()每当我查看查询部分时,我得到的只是一个小方框,它应该向我显示图表,但它一直在加载。任何意见是极大的赞赏。谢谢!
查看完整描述

2 回答

?
倚天杖

TA贡献1828条经验 获得超3个赞

这是运行的完整示例:

import matplotlib.pyplot as plt

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])

这是我的问题

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.5

tipping.input['service'] = 9.8


# Crunch the numbers

tipping.compute()

print (tip)

tip.view(sim=tipping)


plt.show()


查看完整回答
反对 回复 2021-11-09
?
米脂

TA贡献1836条经验 获得超3个赞

由于skfuzzy使用matplotlib和NetworkX底层,您可以尝试使用此代码来显示您的数字:


import matplotlib.pyplot as plt

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()


plt.show()


查看完整回答
反对 回复 2021-11-09
  • 2 回答
  • 0 关注
  • 202 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信