成功解决raise TypeError(‘Unexpected feature_names type‘)TypeError: Unexpected feature_names type


抽屉负责
抽屉负责 2022-09-19 10:04:11 47669
分类专栏: 资讯

成功解决raise TypeError('Unexpected feature_names type')TypeError: Unexpected feature_names type

目录

解决问题

解决思路

解决方法

源代码解析


解决问题

raise TypeError('Unexpected feature_names type')TypeError: Unexpected feature_names type

解决思路

类型错误:意外的 feature_names 类型

解决方法

经过分析发现,
原函数参数要求类型是list类型,
而当前出错的代码却提供了pandas.core.indexes.base.Index类型

feature_names : list, optional.  A list of feature names. It allows to specify feature  names when they are not provided by an estimator object.  This argument may be supported or not, depending on estimator type.

feature_names :列表,可选。 feature 名称列表。 它允许在估算器对象未提供特征名称时指定它们。 根据估算器类型,可能支持或不支持此参数。

源代码解析

  1. def show_weights(estimator, **kwargs):
  2. """ Return an explanation of estimator parameters (weights)
  3. as an IPython.display.HTML object. Use this function
  4. to show classifier weights in IPython.
  5. :func:`show_weights` accepts all
  6. :func:`eli5.explain_weights` arguments and all
  7. :func:`eli5.formatters.html.format_as_html`
  8. keyword arguments, so it is possible to get explanation and
  9. customize formatting in a single call.
  10. Parameters
  11. ----------
  12. estimator : object
  13. Estimator instance. This argument must be positional.
  14. top : int or (int, int) tuple, optional
  15. Number of features to show. When ``top`` is int, ``top``
  16. features with
  17. a highest absolute values are shown. When it is (pos, neg)
  18. tuple,
  19. no more than ``pos`` positive features and no more than
  20. ``neg``
  21. negative features is shown. ``None`` value means no limit.
  22. This argument may be supported or not, depending on
  23. estimator type.
  24. target_names : list[str] or {'old_name': 'new_name'} dict,
  25. optional
  26. Names of targets or classes. This argument can be used to
  27. provide
  28. human-readable class/target names for estimators which
  29. don't expose
  30. clss names themselves. It can be also used to rename
  31. estimator-provided
  32. classes before displaying them.
  33. This argument may be supported or not, depending on
  34. estimator type.
  35. targets : list, optional
  36. Order of class/target names to show. This argument can be
  37. also used
  38. to show information only for a subset of classes. It should
  39. be a list
  40. of class / target names which match either names provided
  41. by
  42. an estimator or names defined in ``target_names``
  43. parameter.
  44. This argument may be supported or not, depending on
  45. estimator type.
  46. feature_names : list, optional
  47. A list of feature names. It allows to specify feature
  48. names when they are not provided by an estimator object.
  49. This argument may be supported or not, depending on
  50. estimator type.
  51. feature_re : str, optional
  52. Only feature names which match ``feature_re`` regex are
  53. shown
  54. (more precisely, ``re.search(feature_re, x)`` is checked).
  55. feature_filter : Callable[[str], bool], optional
  56. Only feature names for which ``feature_filter`` function
  57. returns True
  58. are shown.
  59. show : List[str], optional
  60. List of sections to show. Allowed values:
  61. * 'targets' - per-target feature weights;
  62. * 'transition_features' - transition features of a CRF model;
  63. * 'feature_importances' - feature importances of a decision
  64. tree or
  65. an ensemble-based estimator;
  66. * 'decision_tree' - decision tree in a graphical form;
  67. * 'method' - a string with explanation method;
  68. * 'description' - description of explanation method and its
  69. caveats.
  70. ``eli5.formatters.fields`` provides constants that cover
  71. common cases:
  72. ``INFO`` (method and description), ``WEIGHTS`` (all the rest),
  73. and ``ALL`` (all).
  74. horizontal_layout : bool
  75. When True, feature weight tables are printed horizontally
  76. (left to right); when False, feature weight tables are printed
  77. vertically (top to down). Default is True.
  78. highlight_spaces : bool or None, optional
  79. Whether to highlight spaces in feature names. This is useful
  80. if
  81. you work with text and have ngram features which may
  82. include spaces
  83. at left or right. Default is None, meaning that the value used
  84. is set automatically based on vectorizer and feature values.
  85. include_styles : bool
  86. Most styles are inline, but some are included separately in
  87. <style> tag;
  88. you can omit them by passing ``include_styles=False``.
  89. Default is True.
  90. **kwargs: dict
  91. Keyword arguments. All keyword arguments are passed to
  92. concrete explain_weights... implementations.
  93. Returns
  94. -------
  95. IPython.display.HTML
  96. The result is printed in IPython notebook as an HTML
  97. widget.
  98. If you need to display several explanations as an output of
  99. a single
  100. cell, or if you want to display it from a function then use
  101. IPython.display.display::
  102. from IPython.display import display
  103. display(eli5.show_weights(clf1))
  104. display(eli5.show_weights(clf2))
  105. """
  106. format_kwargs, explain_kwargs = _split_kwargs(kwargs)
  107. expl = explain_weights(estimator, **explain_kwargs)
  108. _set_html_kwargs_defaults(format_kwargs)
  109. html = format_as_html(expl, **format_kwargs)
  110. return HTML(html)
文章知识点与官方知识档案匹配,可进一步学习相关知识

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=1651
赞同 0
评论 0 条
抽屉负责L0
粉丝 0 发表 7 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2691
【软件正版化】软件正版化工作要点  2655
统信UOS试玩黑神话:悟空  2559
信刻光盘安全隔离与信息交换系统  2247
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1117
grub引导程序无法找到指定设备和分区  769
江波龙2025届校园招聘宣讲会行程大放送  28
点击报名 | 京东2025校招进校行程预告  25
海康威视2025校招|海康机器人,邀你共创工业智能化未来!  24
金山办公2024算法挑战赛 | 报名截止日期更新  22
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!