简体   繁体   English

Python 错误 - NotImplementedError: 转换 'py2rpy' 没有为类型的对象定义<class 'ipywidgets.widgets.widget_string.text'> '</class>

[英]Python Error - NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'ipywidgets.widgets.widget_string.Text'>'

I'm getting the error below from some Python code.我从一些 Python 代码中收到以下错误。 Can anyone help me figure out what is going on?谁能帮我弄清楚发生了什么? I tried to embed the full code, but I kept getting an error saying my code was not properly formatted.我试图嵌入完整的代码,但我一直收到错误消息,说我的代码格式不正确。 I'll try to post a reply with the full code!我会尝试用完整的代码回复!

NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'ipywidgets.widgets.widget_string.Text'>' NotImplementedError:没有为“<class 'ipywidgets.widgets.widget_string.Text'>”类型的对象定义转换“py2rpy”

**Code:**

    ---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Input In [122], in <cell line: 1>()
----> 1 get_ipython().run_cell_magic('R', '-i cutoff -i mtry -i ntree -i data -o max_f1 -o max_cut -o max_mtry -o max_ntree -o max_precision -o max_recall', 'library(randomForest)\n\nfrom types import NoneType\nNoneType = type(None)\n\n#from IPython.core.interactiveshell import InteractiveShell\n#InteractiveShell.ast_node_interactivity = "all"\n\n#9-24-2022 SL\n#from rpy2.robjects.conversion import localconverter as lc\n\n#with lc(ro.default_converter + pr.converter):\n#  fileName_c = ro.conversion.py2rpy(fileName)\n#  url_c = ro.conversion.py2rpy(url)\n#ro.globalenv[\'fileName\'] = fileName_c\n#ro.globalenv[\'url\'] = url_c\n\n#from rpy2.robjects import pandas2ri\n\n\n#pandas2ri.activate()\n#end 9-24-2022 SL\n\ndata$target = factor(data$target)\ncutoff_list = unlist(strsplit("0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9",","))  #cutoff 9-24-2022 SL\nmtry_list = unlist(strsplit("2,3,4,5",","))  #mtry 9-24-2022 SL\nntree_list = unlist(strsplit("100,500,1000",","))  #ntree 9-24-2022 SL\nset.seed(830)\nmax_f1 = 0\nmax_cut = 0\nmax_mtry = 0\nmax_ntree = 0\nmax_precision = 0\nmax_recall = 0\n# a nested for loop for ntree, mtry, cutoff?\nfor (cut in cutoff_list )\n{\n    for (Mtry in mtry_list)\n    {\n        for (Ntree in ntree_list)\n        {\n            cut = as.numeric(cut) #9-24-2022 SL cut - should be "cutoff"?\n            Mtry = as.numeric(mtry) #9-24-2022 SL mtry\n            Ntree = as.numeric(NTree) #9-24-2022 SL Ntree\n            fit_data <- randomForest(data$target ~ ., data=data, importance=TRUE, proximity=TRUE, cutoff=c(cut, 1-cut), ntree=Ntree, mtry=Mtry)\n            true_positives = fit_data$confusion[\'1\',\'1\']\n            true_negatives = fit_data$confusion[\'0\',\'0\']\n            false_positives = fit_data$confusion[\'0\',\'1\']\n            false_negatives = fit_data$confusion[\'1\',\'0\']\n            accuracy = (true_positives + true_negatives)/nrow(data)\n            precision = true_positives/(true_positives+false_positives)\n            recall = true_positives/(true_positives + false_negatives)\n            f1_score = 2*((recall*precision)/(precision+recall))\n            if (! is.nan(f1_score) && f1_score > max_f1)\n            {\n                max_f1 = f1_score\n                max_cut = cut\n                max_mtry = Mtry\n                max_ntree = Ntree\n                max_precision = precision\n                max_recall = recall\n            }\n        }\n    }\n}\n\n')

File ~\anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2347, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
   2345 with self.builtin_trap:
   2346     args = (magic_arg_s, cell)
-> 2347     result = fn(*args, **kwargs)
   2348 return result

File ~\anaconda3\lib\site-packages\rpy2\ipython\rmagic.py:755, in RMagics.R(self, line, cell, local_ns)
    753                 raise NameError("name '%s' is not defined" % input)
    754         with localconverter(converter) as cv:
--> 755             ro.r.assign(input, val)
    757 if args.display:
    758     try:

File ~\anaconda3\lib\site-packages\rpy2\robjects\functions.py:203, in SignatureTranslatedFunction.__call__(self, *args, **kwargs)
    201         v = kwargs.pop(k)
    202         kwargs[r_k] = v
--> 203 return (super(SignatureTranslatedFunction, self)
    204         .__call__(*args, **kwargs))

File ~\anaconda3\lib\site-packages\rpy2\robjects\functions.py:118, in Function.__call__(self, *args, **kwargs)
    116 def __call__(self, *args, **kwargs):
    117     cv = conversion.get_conversion()
--> 118     new_args = [cv.py2rpy(a) for a in args]
    119     new_kwargs = {}
    120     for k, v in kwargs.items():
    121         # TODO: shouldn't this be handled by the conversion itself ?

File ~\anaconda3\lib\site-packages\rpy2\robjects\functions.py:118, in <listcomp>(.0)
    116 def __call__(self, *args, **kwargs):
    117     cv = conversion.get_conversion()
--> 118     new_args = [cv.py2rpy(a) for a in args]
    119     new_kwargs = {}
    120     for k, v in kwargs.items():
    121         # TODO: shouldn't this be handled by the conversion itself ?

File ~\anaconda3\lib\functools.py:888, in singledispatch.<locals>.wrapper(*args, **kw)
    884 if not args:
    885     raise TypeError(f'{funcname} requires at least '
    886                     '1 positional argument')
--> 888 return dispatch(args[0].__class__)(*args, **kw)

File ~\anaconda3\lib\site-packages\rpy2\robjects\numpy2ri.py:134, in nonnumpy2rpy(obj)
    129     return ro.default_converter.py2rpy(obj)
    130 elif original_converter is None:
    131     # This means that the conversion module was not "activated".
    132     # For now, go with the default_converter.
    133     # TODO: the conversion system needs an overhaul badly.
--> 134     return ro.default_converter.py2rpy(obj)
    135 else:
    136     # The conversion module was "activated"
    137     return original_converter.py2rpy(obj)

File ~\anaconda3\lib\functools.py:888, in singledispatch.<locals>.wrapper(*args, **kw)
    884 if not args:
    885     raise TypeError(f'{funcname} requires at least '
    886                     '1 positional argument')
--> 888 return dispatch(args[0].__class__)(*args, **kw)

File ~\anaconda3\lib\site-packages\rpy2\robjects\conversion.py:240, in _py2rpy(obj)
    238 if isinstance(obj, _rinterface_capi.SupportsSEXP):
    239     return obj
--> 240 raise NotImplementedError(
    241     "Conversion 'py2rpy' not defined for objects of type '%s'" %
    242     str(type(obj))
    243 )

NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'ipywidgets.widgets.widget_string.Text'>'

Turns out I there were some input parameters that I needed to hit for prior steps to store them properly.事实证明,我需要在前面的步骤中输入一些输入参数才能正确存储它们。 Once I did that, the above error got resolved.一旦我这样做了,上面的错误就得到了解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 脚本中的 RPY2 错误! (未为类型为“的对象定义转换‘py2rpy’<class 'pandas.core.frame.dataframe'> ')</class> - RPY2 error in Python script! (Conversion 'py2rpy' not defined for objects of type '<class 'pandas.core.frame.DataFrame'>') NotImplementedError: 转换 'rpy2py' 没有为类型 ' 的对象定义<class 'rpy2.rinterface.sexpclosure'> ' 只有在我运行代码两次之后</class> - NotImplementedError: Conversion 'rpy2py' not defined for objects of type '<class 'rpy2.rinterface.SexpClosure'>' only after I run the code twice 为什么我收到“模块'rpy2.robjects.conversion'没有属性'py2rpy'”错误? - Why am I getting “module 'rpy2.robjects.conversion' has no attribute 'py2rpy'” error? python ipywidgets 在 widgets.Text 中以编程方式强制峰会 - python ipywidgets force a summit programmatically in a widgets.Text Jupyter笔记本ipywidget未显示小部件无法显示标签类型的Jupyter小部件 - Jupyter notebook ipywidgets not showing widgets Failed to display Jupyter Widget of type Label rpy2在ubuntu上测试获取“ NotImplementedError:从rpy2 DataFrame转换为熊猫的DataFrame” - rpy2 tests getting “NotImplementedError: Conversion from rpy2 DataFrame to pandas' DataFrame” on ubuntu Pyxll&#39;ipywidgets.widgets&#39;重新加载错误 - Pyxll 'ipywidgets.widgets' reloading error 将 ipywidgets.widgets.widget_output.Output 转换为列表 - Converting ipywidgets.widgets.widget_output.Output to a list 为什么 html 文件中没有定义来自 ipywidgets 的小部件? - How come widgets from ipywidgets is not defined in an html file? 为 rpy2 转换 python 对象 - Converting python objects for rpy2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM