I was trying to import Categorical Encoder in sklearn
from sklearn.preprocessing import CategoricalEncoder
But I get the error
ImportError: cannot import name 'CategoricalEncoder' from 'sklearn.preprocessing' (D:\ProgramData\Miniconda3\lib\site-packages\sklearn\preprocessing\__init__.py)
I have version 0.21.3 of sklearn.
I checked online to see the documentation and it seems that CategoricalEncoder was there in version 0.20.dev0 (https://15359-843222-gh.circle-artifacts.com/0/home/ubuntu/scikit-learn/doc/_build/html/stable/modules/generated/sklearn.preprocessing.CategoricalEncoder.html)
But is not there in 0.21.3 (https://scikit-learn.org/stable/modules/classes.html#module-sklearn.preprocessing)
What happened to CategoricalEncoder?
Is there a way I can still use it? Like can I import 2 versions of sklearn and pull it from the 0.20.dev0 version
CategoricalEncoder is only available in the development version 0.20.dev0. Use OneHotEncoder and OrdinalEncoder insted.(see #10521)
Related
I try to do some PCA and TSNE analyses. I want to use sklearn to import the PCA and TSNE package.
Internet says that I should use these imports
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html
However, I get this message when I try to import those.
ImportError: cannot import name 'PCA' from 'sklearn.decomposition' (unknown location)
I did install sklearn and am able to import sklearn.decomposition and sklearn.manifold. However, If I I try to do this:
import sklearn.decomposition as decom
decom.PCA
I get the same ImportError. I tried reinstalling sklearn and updating it, but that doesn't solve the problem. Does one of you have a clue of what I'm doing wrong? I'm using Python 3.7.8 and use jupyter lab with MiniConda.
The documentation of sklearn is version 23.2 and that is the same version as my scikit-learn is.
EDIT: I created a totally new virtual environment and now my dir(decom) is totally different. And those packages for PCA and TSNE are working. Could somebody enlighten me why those are not working in the my current environment? Does it have to do with incompatible packages? I did not get any warning for it. It is sort of solved, yet I'm curious what the reason is and how I can fix it in the future.
I'm am getting this error just in the being of importing my packages. I haven't been able to find the correct remedy to fix the issue. Any help is greatly appreciated.
From what I can tell it looks to maybe be a Tensorflow issue?
from sklearn.model_selection import train_test_split
import pandas as pd
import tensorflow as tf
import tensorflow_hub as hub
from datetime import datetime
import bert
from bert import run_classifier
from bert import optimization
from bert import tokenization
found this
Background
Colab has two versions of TensorFlow pre-installed: a 2.x version and a 1.x version. Colab uses TensorFlow 2.x by default, though you can switch to 1.x by the method shown below.
Specifying the TensorFlow version
Running import tensorflow will import the default version (currently 2.x). You can use 1.x by running a cell with the tensorflow_version magic before you run import tensorflow.
[ ]
%tensorflow_version 1.x
TensorFlow 1.x selected.
more detail :
https://colab.research.google.com/notebooks/tensorflow_version.ipynb#scrollTo=NeWVBhf1VxlH
You seem to have TensorFlow 2.x while the bert module uses TensorFlow 1.x. You can verify here that Tensorflow 1.x has the tf.train.Optimizer module while according to this, Tensorflow 2.x has no such module.
Make sure you install the Tensorflow version that bert requires
I am following a deep learning tutorial book in Japanese and it is using MNIST for its handwritten images. It has the code from dataset.mnist import load_dataset, and when I tried it, it did not work, gave an error saying no such module named dataset.mnist. I have downloaded the modules dataset and mnist individually using pip. The book recommended to use Anaconda, but I have tried it to no success.
How can I use the module dataset.mnist?
The first question I want to ask you is which deep learning framework are you working with for solving your problem.
There are many deep learning frameworks. PyTorch, Tensorflow, and Keras are examples of such frameworks.
1) If you are working with PyTorch framework then you should import the torch framework using the command.
import torch
and then you can import MNIST dataset using the command
from torchvision.datasets import MNIST
2) For Keras framework use the following commands for importing MNIST dataset.
import keras
from keras.datasets import mnist
NOTE: This can be written as well for better understanding of your problem.
import keras
from keras.datasets as datasets
and then you can import MNIST dataset using thedatasets which is an alias of keras.datasets
Similarly, you can import MNIST dataset in other frameworks as well.
Hope this will be of your help.
Adding on to #SauravRai's Answer
For tensorflow :
from tensorflow.examples.tutorials.mnist import input_data
input_data.read_data_sets('my/directory')
I am trying to play around with machine learning but I am having issues with sklearn and importing cross_validation. I keep getting error messages saying
ImportError: cannot import name 'cross_validation' from 'sklearn' (C:\Python3.7\lib\site-packages\sklearn\__init__.py)
When I check pip list, it is definitely there; showing sklearn 0.0. There seems to be no other version of sklearn apart from 0.0.
Someone please help.
I am using sentdex's youtube tutorial series on regression for this code.
import pandas as pd
import sklearn
from sklearn import preprocessing, cross_validation,svm
from sklearn import LinearRegression
That is because Sklearn doesn't have any cross_validation module.
Try using:
from sklearn import model_selection
The cross_validation model has been deprecated.
I am trying to learn data analysis using the iris data set. So I just am copying the already written code for this subject and I get the following error regarding the libraries :
Traceback (most recent call last):
File "iris.py", line 6, in <module>
from sklearn import model_selection
ImportError: cannot import name model_selection
And here is how I import this module:
from sklearn import model_selection
I am using python 2.7,
What could be the problem?
I suspect there might be a problem with the version!right?or not?
Please don't suggest Anaconda, I am not willing to use it.
Thanks a bunch
sklearn.model_selection is available for version 0.18 or late version
Please update your sklearn by pip or other tools
org website
http://scikit-learn.org/stable/whats_new.html#version-0-18
Version 0.18
September 28, 2016
Last release with Python 2.6 support
Scikit-learn 0.18 will be the last version of scikit-learn to support Python 2.6. Later versions of scikit-learn will require Python 2.7 or above.
Model Selection Enhancements and API Changes
The model_selection module
The new module sklearn.model_selection, which groups together the functionalities of formerly sklearn.cross_validation, sklearn.grid_search and sklearn.learning_curve, introduces new possibilities such as nested cross-validation and better manipulation of parameter searches with Pandas.
Many things will stay the same but there are some key differences. Read below to know more about the changes.
Data-independent CV splitters enabling nested cross-validation