I'm getting this error while trying to import the imputer module
from sklearn.preprocessing import Imputer
Error:
ImportError Traceback (most recent call last)
<ipython-input-10-40d42fb5b303> in <module>
1 # Import the Imputer module
----> 2 from sklearn.preprocessing import Imputer
3 from sklearn.svm import SVC
4
5 # Setup the Imputation transformer: imp
ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (C:\Users\MOSTAFA\anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py)
https://scikit-learn.org/stable/modules/generated/sklearn.impute.SimpleImputer.html
New in version 0.20: SimpleImputer replaces the previous sklearn.preprocessing.Imputer estimator which is now removed.
So, beginning with sklearn 0.20 you need to use SimpleImputer instead.
try: from sklearn.impute import SimpleImputer
Related
I am working on healthcare image dataset for image segmentation. More specific, it is "Spinal Cord Gray Matter Segmentation Using PyTorch". When I am trying to install libraries initially using this code:
!pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-linux_x86_64.whl
!pip3 install torchvision
!pip install medicaltorch
!pip3 install numpy==1.14.1
it is showing some errors in between required satisfied like this:
1st screenshot
2nd screenshot
After that I am importing libraries:
from collections import defaultdict
import time
import os
import numpy as np
from tqdm import tqdm
from medicaltorch import datasets as mt_datasets
from medicaltorch import models as mt_models
from medicaltorch import transforms as mt_transforms
from medicaltorch import losses as mt_losses
from medicaltorch import metrics as mt_metrics
from medicaltorch import filters as mt_filters
import torch
from torchvision import transforms
from torch.utils.data import DataLoader
from torch import autograd, optim
import torch.backends.cudnn as cudnn
import torch.nn as nn
import torchvision.utils as vutils
cudnn.benchmark = True
import matplotlib.pyplot as plt
%matplotlib inline
This importing is throwing an error like this:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-80b8c583d1fe> in <module>()
20
21
---> 22 from medicaltorch import datasets as mt_datasets
23 from medicaltorch import models as mt_models
24 from medicaltorch import transforms as mt_transforms
/usr/local/lib/python3.7/dist-packages/medicaltorch/datasets.py in <module>()
11 from torch.utils.data import Dataset
12 import torch
---> 13 from torch._six import string_classes, int_classes
14
15 from PIL import Image
ImportError: cannot import name 'int_classes' from 'torch._six' (/usr/local/lib/python3.7/dist-packages/torch/_six.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
can someone help me resolve this?
In pytorch 1.9 int_classes variable in torch._six was removed. facebookresearch/TimeSformer#47
Use this code instead.
from torch._six import string_classes
int_classes = (bool, int)
See source here: https://github.com/visionml/pytracking/issues/272
I'm trying to import the following:
from tensorflow.keras.applications import EfficientNetB5
from tensorflow.keras import models
from tensorflow.keras import *
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing.image import image_dataset_from_directory
And I get this error:
ImportError Traceback (most recent call last)
<ipython-input-1-5f46c7257169> in <module>
3 from tensorflow.keras import *
4 from tensorflow.keras.preprocessing.image import ImageDataGenerator
----> 5 from tensorflow.keras.preprocessing.image import image_dataset_from_directory
6 import os
7 import shutil
ImportError: cannot import name 'image_dataset_from_directory'
I'm using python3.9, tf-2.6. I also tried to install tf-nightly/keras-nightly, facing the same error. Any idea about how can I solve it? Last week I can ran the code, but now I'm completely stuck.
I tried to install segmentation-models using.
!pip install -U segmentation-models==0.2.1
import tensorflow as tf
import tensorflow.keras as keras
print(tf.__version__)
print(keras.__version__)
Output:
2.4.1
2.4.0
# Tried for import
import segmentation_models as sm
Resulted in error: ModuleNotFoundError: No module named 'keras.legacy'
Following is the stack trace
stack Trace:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-16-7b5049dd4be0> in <module>()
----> 1 import segmentation_models as sm
6 frames
/usr/local/lib/python3.7/dist-packages/segmentation_models/__init__.py in <module>()
4
5 from .unet import Unet
----> 6 from .fpn import FPN
7 from .linknet import Linknet
8 from .pspnet import PSPNet
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/__init__.py in <module>()
----> 1 from .model import FPN
2
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/model.py in <module>()
----> 1 from .builder import build_fpn
2 from ..backbones import get_backbone, get_feature_layers
3 from ..utils import freeze_model
4 from ..utils import legacy_support
5
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/builder.py in <module>()
6 from keras.models import Model
7
----> 8 from .blocks import pyramid_block
9 from ..common import ResizeImage
10 from ..common import Conv2DBlock
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/blocks.py in <module>()
1 from keras.layers import Add
2
----> 3 from ..common import Conv2DBlock
4 from ..common import ResizeImage
5 from ..utils import to_tuple
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/__init__.py in <module>()
1 from .blocks import Conv2DBlock
----> 2 from .layers import ResizeImage
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/layers.py in <module>()
2 from keras.engine import InputSpec
3 from keras.utils import conv_utils
----> 4 from keras.legacy import interfaces
5 from keras.utils.generic_utils import get_custom_objects
6
ModuleNotFoundError: No module named 'keras.legacy'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Solution Tried:
To downgrade both tensorflow and keras to
!pip install tensorflow==2.2.0
!pip install keras==2.3.1
But it is creating conflict between the tensorflow.keras and keras.
Is there any way to work this using tensorflow.keras?
As of now the following approach is working.
Do not try with specific version of segmentation_models module.
#install this way
!pip3 install tensorflow==2.2
!pip3 install keras==2.3.1
!pip3 install -U segmentation-models
import tensorflow as tf
import tensorflow.keras as keras
import segmentation_models as sm
Now segmentation_models imported successfully.
Trying to import Imputer from sklearn.preprocessing,
import pandas as pd
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
#PART WHERE ERROR OCCURS:-
from sklearn.preprocessing import Imputer
Shows "ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (/home/codeknight13/anaconda3/lib/python3.7/site-packages/sklearn/preprocessing/_init_.py)"
from sklearn.preprocessing import Imputer was deprecated with scikit-learn v0.20.4 and removed as of v0.22.2. See the sklean changelog.
from sklearn.impute import SimpleImputer
import numpy as np
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
pip install scikit-learn==0.20.4 or conda install scikit-learn=0.20.4 are not a good options because scikit-learn==0.20.4 is more than 3 years out of date.
I am trying to do this:
from sklearn.model_selection import train_test_split
and getting an error:
In [31]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-31-73edc048c06b> in <module>()
----> 1 from sklearn.model_selection import train_test_split
/usr/local/lib/python3.6/site-packages/sklearn/model_selection/__init__.py in <module>()
----> 1 from ._split import BaseCrossValidator
2 from ._split import KFold
3 from ._split import GroupKFold
4 from ._split import StratifiedKFold
5 from ._split import TimeSeriesSplit
/usr/local/lib/python3.6/site-packages/sklearn/model_selection/_split.py in <module>()
29 from ..externals.six import with_metaclass
30 from ..externals.six.moves import zip
---> 31 from ..utils.fixes import signature, comb
32 from ..base import _pprint
33
ImportError: cannot import name 'comb'
any help would be much apreciated.
SciPy >=0.19 uses from scipy.special import comb instead of from scipy.misc import comb. https://github.com/scikit-learn/scikit-learn/pull/9046
utils/fixes.py source
try: # SciPy >= 0.19
from scipy.special import comb, logsumexp
except ImportError:
from scipy.misc import comb, logsumexp # noqa
I had the same error. conda remove --name your environment --all. Next, re-install the environment. It worked for me.