Unable to import patch sklearn - python

after importing and installing required packages and libraries I am encountering an import error on patch_sklearn().
from sklearnx import patch_sklearn()
patch_sklearn()
ImportError: cannot import name 'sparse_lsqr' from 'sklearn.utils.fixes' (C:\Users\yogis\AppData\Roaming\Python\Python38\site-packages\sklearn\utils\fixes.py)

Didn't know what you want to do here.
But you can try this:
from sklearn.feature_extraction.image import extract_patches_2d

You must install scikit learn version 1.0 and not 1.1
pip install scikit-learn==1.0
Then after this, restart kernel. If it doesn't work after this, I also had to force reinstall the other packages for conda.
conda install numpy scipy joblib scikit-learn --force-reinstall
and then restart kernel. It worked fine. This is a known bug and is fixed on pypi releases but not yet on conda.

Related

ImportError: cannot import name 'DecisionBoundaryDisplay' from 'sklearn.inspection'

I imported sklearn DecisionBoundaryDisplay via the below command in my Google Colab file.
from sklearn.inspection import DecisionBoundaryDisplay
And I'm getting the following error.
ImportError: cannot import name 'DecisionBoundaryDisplay' from 'sklearn.inspection'
I even installed the following packages & also tried by restarting my runtime but still I'm getting the error.
!pip install --upgrade scikit-learn
!pip install scipy
!pip3 install -U scikit-learn scipy matplotlib
How to fix this issue?
what worked for me was installing scikit learn 1.1.0, i had version 1.0.2 before and got the same error you're encountering.
pip install -U scikit-learn --user
Hope it helps.
It seems DecisionBoundaryDisplay is a new feature and it is currently in an unstable development version. To use it, you need to install the nightly build.

Pycaret cannot imported due to another import error

ImportError: cannot import name '_joblib_parallel_args' from 'sklearn.utils.fixes' (c:\users\ezgi\appdata\local\programs\python\python38\lib\site-packages\sklearn\utils\fixes.py)
To fix I update sklearn library. But, it don't work. Anyone know the reason behind it?
I update sklearn with
pip install --upgrade scikit-learn
Also, uninstall and install it with pip.
This is because one of pycaret's dependencies (imbalanced-learn) fails with the latest version of sklearn
https://github.com/scikit-learn-contrib/imbalanced-learn/issues/894
A temporary workaround until this is fixed would be to use a lower version of sklearn. If you are using pip install pycaret, then you need to use a version of sklearn < 1.0.0

\_tfq_simulate_ops.so not found while import tensorflow_quantum

Trying import of initial libraries related to tensorflow_quantum:
import tensorflow as tf
import tensorflow_quantum as tfq
import cirq
import sympy
import numpy as np
Getting error in 2nd line:
File "Path_to_anaconda_site_packages\tensorflow_core\python\framework\load_library.py", line 61, in load_op_library
lib_handle = py_tf.TF_LoadLibrary(library_filename)
NotFoundError: Path_To_Tensorflow_Quantum\core\ops\_tfq_simulate_ops.so not found
This is the solution provided by the Tensorflow team, it worked for me.
!pip install tensorflow-gpu==2.1.0
!pip install cirq==0.7.0 pathos==0.2.5 tensorflow-quantum==0.2.0
Do following steps:
!pip uninstall tensorflow
!pip install tensorflow
then restart runtime to import the packages.It works.
This might be something that would be worth raising as an issue on the TensorFlow Quantum Github here (https://github.com/tensorflow/quantum/issues). Without much information on the platform your are using or even what python version you have it might be hard to diagnose the problem here, but a quick fix you could try might be that you have an older version of TensorFlow installed. TensorFlow Quantum requires tf == 2.1.0.
pip install --upgrade pip
pip install --upgrade tensorflow
If that doesn't do it, then it might be worth opening an issue on github and giving a few more details on there :)

Numpy version issue when using astropy

I am currentling trying to use a package I installed (stsynphot), but I have the following error when typing import stsynphot as stsyn
ImportError: Numpy version 1.9.0 or later must be installed to use Astropy
I was curious so just to try, I tried import astropy and of course had the same error.
Nevertheless, I do have numpy 1.14 installed, I have tried all the upgrade and reinstall procedures but I still have the issue.
Any ideas ?
Thanks !
Try this:
pip install --user astropy[all]
and for the stsynphot package follow these steps: https://stsynphot.readthedocs.io/en/latest/

ImportError: cannot import name 'MultiOutputMixin' from 'sklearn.base'

I just want to do a linear regression with scikit-learn. When I try to import the linear model package the error message from the title appears.
I tried to follow the solution from a similar problem (link). The suggestion is basically to just get rid of the part of the code where it requests for the "MultipleOutputMixin" thingy.
When I do this, of course the MultiOuputMixin is no longer the problem, but it derives in an error at the line marked as 22 in the error message shown below.
Any ideas on what can I do to avoid the problem?
Thanks in advance for your help! :)
Python version = 3.70
scikit-learn verion = 0.21.2
This is what I'm doing:
from sklearn import linear_model
This is the error that I get:
ImportError Traceback (most recent call last)
<ipython-input-46-1c4d4ebecc3f> in <module>()
1 # Select a linear
----> 2 from sklearn import linear_model
C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\linear_model\__init__.py in <module>()
13
14 from .bayes import BayesianRidge, ARDRegression
---> 15 from .least_angle import (Lars, LassoLars, lars_path, lars_path_gram, LarsCV,
16 LassoLarsCV, LassoLarsIC)
17 from .coordinate_descent import (Lasso, ElasticNet, LassoCV, ElasticNetCV,
C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\linear_model\least_angle.py in <module>()
18
19 from .base import LinearModel
---> 20 from ..base import RegressorMixin, MultiOutputMixin
21 from ..utils import arrayfuncs, as_float_array, check_X_y
22 from ..model_selection import check_cv
ImportError: cannot import name 'MultiOutputMixin' from 'sklearn.base' (C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\base.py)
I have encountered a similar problem. I could solve by opening a new IPython console.
I don't think so it's a good idea to modify library related files without understanding it fully. I got this issue when I had updated scikit learn package. It worked after I launched a new shell.
!pip install scikit-learn==0.18.2 is the wrong advice.
You'll need scikit-learn version 0.22 or higher.
This was solved after shutting down the existing notebook and reopening it from home page. It may need a restart is what I got to know.
uninstall and install the imblearn again :
pip install imblearn
with the updated sklearn packages this worked for me.
From installation anacoda prompt:
Installing collected packages: imblearn, scikit-learn
Attempting uninstall: scikit-learn
Found existing installation: scikit-learn 0.20.3
Uninstalling scikit-learn-0.20.3:
Successfully uninstalled scikit-learn-0.20.3
Successfully installed imblearn-0.0 scikit-learn-0.23.1
Problem reasons
This issue occurs when you tried to install a new version of scikit-learn, I encountered the same issue while trying to install sklearn (1.0) while an old scikit-learn version (0.22.2) was installed.
I encountered this problem, because I had to update the version of sciki-learn on Colab and retrain my model to avoid some warnings with the production environment. The problem was as shown below:
UserWarning: Trying to unpickle estimator TfidfVectorizer from version 0.22.2.post1 when using version 1.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
So, when I did this:
!pip install scikit-learn==1.0
I got the error below while importing the following libraries:
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
This is the rrror:
ImportError: cannot import name '_OneToOneFeatureMixin' from 'sklearn.base' (/usr/local/lib/python3.7/dist-packages/sklearn/base.py)
How to fix it
This problem can be fixed by simply trying to restart the runtime environment, or open a new notebook (runtime env restart by default as mentioned by AnandOCF)
This worked for me.
Activate your conda env
conda activate 'your_env_name'
Install imblearn library using pip if you haven't
pip install imblearn
Again install imbalanced-learn library using conda
conda install -c conda-forge imbalanced-learn
Then, you should be able to import without any errors.
You can run the following command on your notebook to solve the issue:
!pip install scikit-learn==0.18.2

Categories

Resources