I am trying to import imblearn into my python notebook after installing the required modules. However, I am getting the following error:
在安装了所需的模块后,我正在尝试将imblearn导入到我的Python笔记本中。但是,我收到以下错误:
Additional info: I am using a virtual environment in Visual Studio Code.
附加信息:我使用的是一个用Visual Studio代码编写的虚拟环境。
I've made sure that venv was selected as interpreter and as the notebook kernel. I've reloaded the window and restarted the kernel several times. I have also uninstalled and installed imbalanced-learn and scikit-learn several times, with and without "--upgrade". I'm still getting the same error.
我已经确定venv被选为解释器和笔记本内核。我已经重新加载了窗口,并多次重新启动了内核。我还卸载和安装了几次不平衡-学习和SCRICKIT-学习,有和没有“--升级”。我仍然收到相同的错误。
Edit: Full traceback of error
编辑:全面回溯错误
{
"name": "ImportError",
"message": "cannot import name '_MissingValues' from 'sklearn.utils._param_validation' (c:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\sklearn\\utils\\_param_validation.py)",
"stack": "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)\nCell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mimblearn\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[39m# Data Processing\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mpandas\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mpd\u001b[39;00m\n\nFile \u001b[1;32mc:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\imblearn\\__init__.py:52\u001b[0m\n\u001b[0;32m 48\u001b[0m sys\u001b[39m.\u001b[39mstderr\u001b[39m.\u001b[39mwrite(\u001b[39m\"\u001b[39m\u001b[39mPartial import of imblearn during the build process.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\"\u001b[39m)\n\u001b[0;32m 49\u001b[0m \u001b[39m# We are not importing the rest of scikit-learn during the build\u001b[39;00m\n\u001b[0;32m 50\u001b[0m \u001b[39m# process, as it may not be compiled yet\u001b[39;00m\n\u001b[0;32m 51\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m---> 52\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m \u001b[39mimport\u001b[39;00m (\n\u001b[0;32m 53\u001b[0m combine,\n\u001b[0;32m 54\u001b[0m ensemble,\n\u001b[0;32m 55\u001b[0m exceptions,\n\u001b[0;32m 56\u001b[0m metrics,\n\u001b[0;32m 57\u001b[0m over_sampling,\n\u001b[0;32m 58\u001b[0m pipeline,\n\u001b[0;32m 59\u001b[0m tensorflow,\n\u001b[0;32m 60\u001b[0m under_sampling,\n\u001b[0;32m 61\u001b[0m utils,\n\u001b[0;32m 62\u001b[0m )\n\u001b[0;32m 63\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39m_version\u001b[39;00m \u001b[39mimport\u001b[39;00m __version__\n\u001b[0;32m 64\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mbase\u001b[39;00m \u001b[39mimport\u001b[39;00m FunctionSampler\n\nFile \u001b[1;32mc:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\imblearn\\combine\\__init__.py:5\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39m\"\"\"The :mod:`imblearn.combine` provides methods which combine\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[39mover-sampling and under-sampling.\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m----> 5\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39m_smote_enn\u001b[39;00m \u001b[39mimport\u001b[39;00m SMOTEENN\n\u001b[0;32m 6\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39m_smote_tomek\u001b[39;00m \u001b[39mimport\u001b[39;00m SMOTETomek\n\u001b[0;32m 8\u001b[0m __all__ \u001b[39m=\u001b[39m [\u001b[39m\"\u001b[39m\u001b[39mSMOTEENN\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mSMOTETomek\u001b[39m\u001b[39m\"\u001b[39m]\n\nFile \u001b[1;32mc:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\imblearn\\combine\\_smote_enn.py:12\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mbase\u001b[39;00m \u001b[39mimport\u001b[39;00m clone\n\u001b[0;32m 10\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m \u001b[39mimport\u001b[39;00m check_X_y\n\u001b[1;32m---> 12\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mbase\u001b[39;00m \u001b[39mimport\u001b[39;00m BaseSampler\n\u001b[0;32m 13\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mover_sampling\u001b[39;00m \u001b[39mimport\u001b[39;00m SMOTE\n\u001b[0;32m 14\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mover_sampling\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mbase\u001b[39;00m \u001b[39mimport\u001b[39;00m BaseOverSampler\n\nFile \u001b[1;32mc:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\imblearn\\base.py:21\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmulticlass\u001b[39;00m \u001b[39mimport\u001b[39;00m check_classification_targets\n\u001b[0;32m 20\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m \u001b[39mimport\u001b[39;00m check_sampling_strategy, check_target_type\n\u001b[1;32m---> 21\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39m_param_validation\u001b[39;00m \u001b[39mimport\u001b[39;00m validate_parameter_constraints\n\u001b[0;32m 22\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39m_validation\u001b[39;00m \u001b[39mimport\u001b[39;00m ArraysTransformer\n\u001b[0;32m 25\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39mSamplerMixin\u001b[39;00m(BaseEstimator, metaclass\u001b[39m=\u001b[39mABCMeta):\n\nFile \u001b[1;32mc:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\imblearn\\utils\\_param_validation.py:908\u001b[0m\n\u001b[0;32m 906\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39m_param_validation\u001b[39;00m \u001b[39mimport\u001b[39;00m generate_valid_param \u001b[39m# noqa\u001b[39;00m\n\u001b[0;32m 907\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39m_param_validation\u001b[39;00m \u001b[39mimport\u001b[39;00m validate_parameter_constraints \u001b[39m# noqa\u001b[39;00m\n\u001b[1;32m--> 908\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mutils\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39m_param_validation\u001b[39;00m \u001b[39mimport\u001b[39;00m (\n\u001b[0;32m 909\u001b[0m HasMethods,\n\u001b[0;32m 910\u001b[0m Hidden,\n\u001b[0;32m 911\u001b[0m Interval,\n\u001b[0;32m 912\u001b[0m Options,\n\u001b[0;32m 913\u001b[0m StrOptions,\n\u001b[0;32m 914\u001b[0m _ArrayLikes,\n\u001b[0;32m 915\u001b[0m _Booleans,\n\u001b[0;32m 916\u001b[0m _Callables,\n\u001b[0;32m 917\u001b[0m _CVObjects,\n\u001b[0;32m 918\u001b[0m _InstancesOf,\n\u001b[0;32m 919\u001b[0m _IterablesNotString,\n\u001b[0;32m 920\u001b[0m _MissingValues,\n\u001b[0;32m 921\u001b[0m _NoneConstraint,\n\u001b[0;32m 922\u001b[0m _PandasNAConstraint,\n\u001b[0;32m 923\u001b[0m _RandomStates,\n\u001b[0;32m 924\u001b[0m _SparseMatrices,\n\u001b[0;32m 925\u001b[0m _VerboseHelper,\n\u001b[0;32m 926\u001b[0m make_constraint,\n\u001b[0;32m 927\u001b[0m validate_params,\n\u001b[0;32m 928\u001b[0m )\n\n\u001b[1;31mImportError\u001b[0m: cannot import name '_MissingValues' from 'sklearn.utils._param_validation' (c:\\Users\\wen\\OneDrive\\Desktop\\Colab_Notebooks\\.venv\\Lib\\site-packages\\sklearn\\utils\\_param_validation.py)"
}
The versions of the modules are as follows:
这些模块的版本如下:
scikit-learn 1.3.0
SCRICK套件-学习1.3.0
imblearn 0.0
IMBLINE 0.0
imbalanced-learn 0.10.1
不平衡-学习0.10.1
更多回答
what versions of skl and imb? Always paste errors as text (not image), and expand to the full traceback (see the last line).
SKL和IMB的哪些版本?始终将错误粘贴为文本(而不是图像),并展开到完整的回溯(请参见最后一行)。
I'm sorry for the format. Please refer to the edits made and let me know if you need additional info.
我对这种格式表示歉意。请参考所做的编辑,如果需要更多信息,请让我知道。
This has been opened as an issue at imblearn: github.com/scikit-learn-contrib/imbalanced-learn/issues/995 It looks like they were importing some private objects from sklearn, which don't need to go through deprecation cycles, and got caught with a broken import in the new skl1.3. imblearn's last merged pull request was in December 2022...
这已经在imblearn:github.com/scikit-learn-contrib/imbalanced-learn/issues/995上作为一个问题被公开了。看起来他们是在从skLearning导入一些私有对象,这些对象不需要经历弃用周期,但在新的skl1.3中发现了一个损坏的导入。IMBLUNN上一次合并的撤回请求是在2022年12月...
优秀答案推荐
I was having the same issue, downgrading to scikit-learn 1.2.2 fixed it for me
我遇到了同样的问题,降级到scikit-learn 1.2.2为我修复了它
I updated my scikit-learn to 1.3.0 and it started raising this error. I think there is a bug with the latest version or the name might have been changed. Try downgrading the version of scikit-learn to 1.2.X, It will solve the problem.
我将我的SCRICKIT-LEARN更新到了1.3.0,它开始提示这个错误。我认为最新版本有错误,或者名称可能被更改了。试着把SCRICKIT-LEARN的版本降级到1.2.X,问题就解决了。
I can reproduce the above issue. Nonetheless, after I restart My Kernal(In Pycharm Jupiter), I find the issue is resolved
我可以转载上面的问题。尽管如此,在我重新启动我的内核(在PyCharm Jupiter中)之后,我发现问题已经解决了
I did this and fixed it
我做了这个并把它修好了
pip uninstall scikit-learn
then i used
然后我用
pip install scikit-learn==1.2.2
"git clone https://github.com/scikit-learn-contrib/imbalanced-learn.git
cd imbalanced-learn"
Use this command to clone this directory from Github then go to imblearn directory on your local machine and replace it with the one you find in the package you have just downloaded
“Git CLONE https://github.com/scikit-learn-contrib/imbalanced-learn.git CD不平衡-学习”使用此命令从Github克隆此目录,然后转到本地计算机上的imblearn目录,并将其替换为您在刚下载的包中找到的目录
the problem is that in sklearn the name is MissingValues meanwhile in imblearn param_validation was _MissingValues which fixed in the new package of imblearn .
问题是,在sklearn中,名称是MissingValues,而在imblain中,param_valify是_MissingValues,它修正了新的imblain包。
All you have to do is Upgrade imblearn to recent version
你所要做的就是升级到最新的版本
I am also facing same error while importing below :
在导入以下内容时,我也遇到了相同的错误:
from imblearn.combine import SMOTETomek
from imblearn.under_sampling import NearMiss
I just downgrade the version of scikit-learn
我刚刚降级了SCRICKIT的版本-学习
Steps to resolve above issue :
解决上述问题的步骤:
pip uninstall scikit-learn
pip install scikit-learn==1.2.2
If does not work then restart kernel.
如果不工作,则重新启动内核。
更多回答
please edit the title to include scikit-learn rather than imblearn
请将标题编辑为包括SCRICKIT-学习而不是不学习
Downgraded to 1.2.1 and worked.
已降级到1.2.1并已运行。
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
您的答案可以通过其他支持信息来改进。请编辑以添加更多详细信息,如引用或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。
我是一名优秀的程序员,十分优秀!