Keras, tensorflow import error - keras

Need help.
(I also checked thread: How do I install Keras and Theano in Anaconda Python on Windows?)
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.recurrent import LSTM
Although I have done everything explained in this thread I keep getting an error for the above prompts.
The error message when I place the cursor on the statements:
Unable to resolve "keras.models". Intellisense may be missing for this module
Unable to resolve "keras.layers.core". Intellisense may be missing for this module
Unable to resolve "keras.layers.recurrent". Intellisense may be missing for this module
I un-istalled, re-installed, deleted theano, updated keras. everything but nothing changed.
Could anyone come up with a possible solution?
thank you

Related

getting error 'tensorflow.python.ops.rnn_cell_impl' has no attribute '_linear'

I tried the below line of code, but it is giving me the below error
y = rnn_cell_impl._linear(slot_inputs, attn_size, True)
AttributeError: module 'tensorflow.python.ops.rnn_cell_impl' has no attribute '_linear'
I am currently using Tensorflow version 2.10, I tried with all possible solutions by using
#from tensorflow.contrib.rnn.python.ops import core_rnn_cell
or
#from tensorflow.keras.layers import RNN
still no solution.
Can someone help me with the same?

Unable to import 'MinMaxScaler' from sklearn.preprocessing

I tried all possible ways and checked everywhere, but I couldn't find the ideal solution.
Uninstalled sklearn, scikit-learn
Installed sklearn 0.23
Upgraded sklearn
but I still didn't succeed.
ImportError: cannot import name 'MinMaxScalar' from 'sklearn.preprocessing' (C:\Users\MY PC\anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py)
You should change the letter A to an E, so MinMaxScalar changes to MinMaxScaler.
Change the last letter a to e in class name
from sklearn.preprocessing import MinMaxScaler

I recently installed a new library for python, but the classes aren't being recognized

I've been using Google CoLab for a project and recently imported the library pycotools3 from a public receptacle to help move some data I have over to COPASI. However, though pycotools3 is recognized by CoLab, none of its classes are.
For instance, when I try any of the following:
from pycotools3 import model
from pycotools3.model import model
from pycotools3 import Model
from pycotools3.model import Model
I receive the error message: "cannot import name 'model'" or "No module named 'pycotools.model'".
The same thing happens with any of the other classes (tasks and viz).
Any ideas on why this is happening or how to fix it?
I think I figured out the problem, so I wanted to answer this in case anyone else has a similar issue. Numpy and scipy, which pycotools3 interacts with, were not up to date. I had updated them for this project, but never restarted my runtime. After restarting my runtime on CoLab, 'model' was recognized.

SKLearn 0.20.2 - Import error with RandomizedPCA?

I'm trying to do the Udacity mini project and I've got the latest version of the SKLearn library installed (20.2).
When I run:
from sklearn.decomposition import RandomizedPCA
I get the error:
ImportError: cannot import name 'RandomizedPCA' from 'sklearn.decomposition' (/Users/kintesh/Documents/udacity_ml/python3/venv/lib/python3.7/site-packages/sklearn/decomposition/__init__.py)
I actually even upgraded the version using:
pip3 install -U scikit-learn
Which upgraded from 0.20.0 to 0.20.2, which also uninstalled and reinstalled... so I'm not sure why it can't initialise sklearn.decomposition.
Are there any solutions here that might not result in completely uninstalling python3 from my machine?! Would ideally like to avoid that.
Any help would be thoroughly appreciated!
Edit:
I'm doing some digging and trying to fix this, and it appears as though the __init__.py file in the decomposition library on the SKLearn GitHub doesn't reference RandomizedPCA... has it been removed or something?
Link to the GitHub page
As it turns out, RandomizePCA() was depreciated in an older version of SKLearn and is simply a parameter in PCA().
You can fix this by changing the import statement to:
from sklearn.decomposition import PCA as RandomizedPCA
... and then your classifier looks like this:
pca = RandomizedPCA(n_components=n_components, svd_solver='randomized', whiten=True).fit(X_train)
However, if you're here because you're doing the Udacity Machine Learning course on Eigenfaces.py, you'll notice that the PIL library is also deprecated.
Unfortunately I don't have a solution for that one, but here's the GitHub issue page, and here's a kind hearted soul that used a Jupyter Notebook to solve their mini-project back when these repositories worked.
I hope this helps, and gives enough information for the next person to get into Machine Learning. If I get some time I might take a crack at recoding eigenfaces.py for SKLearn 0.20.2, but for now I'm just going to crack on with the rest of this course.
In addition to what #Aaraeus said, the PIL library has been forked to Pillow.
You can fix the PIL import error using
pip3 install pillow

Why the import "from tensorflow.train import Feature" doesn't work

That's probably totally noob question which has something to do with python module importing, but I can't understand why the following is valid:
> import tensorflow as tf
> f = tf.train.Feature()
> from tensorflow import train
> f = train.Feature()
But the following statement causes an error:
> from tensorflow.train import Feature
ModuleNotFoundError: No module named 'tensorflow.train'
Can please somebody explain me why it doesn't work this way? My goal is to use more short notation in the code like this:
> example = Example(
features=Features(feature={
'x1': Feature(float_list=FloatList(value=feature_x1.ravel())),
'x2': Feature(float_list=FloatList(value=feature_x2.ravel())),
'y': Feature(int64_list=Int64List(value=label))
})
)
tensorflow version is 1.7.0
Solution
Replace
from tensorflow.train import Feature
with
from tensorflow.core.example.feature_pb2 import Feature
Explanation
Remarks about TensorFlow's Aliases
In general, you have to remember that, for example:
from tensorflow import train
is actually an alias for
from tensorflow.python.training import training
You can easily check the real module name by printing the module. For the current example you will get:
from tensorflow import train
print (train)
<module 'tensorflow.python.training.training' from ....
Your Problem
In Tensorflow 1.7, you can't use from tensorflow.train import Feature, because the from clause needs an actual module name (and not an alias). Given train is an alias, you will get an ImportError.
By doing
from tensorflow import train
print (train.Feature)
<class 'tensorflow.core.example.feature_pb2.Feature'>
you'll get the complete path of train. Now, you can use the import path as shown above in the solution above.
Note
In TensorFlow 1.9.0, from tensorflow.train import Feature will work, because tensorflow.train is an actual package, which you can therefore import. (This is what I see in my installed Tensorflow 1.9.0, as well as in the documentation, but not in the Github repository. It must be generated somewhere.)
Info about the path of the modules
You can find the complete module path in the docs. Every module has a "Defined in" section. See image below (taken from Module: tf.train):
I would advise against importing Feature (or any other object) from the non-public API, which is inconvenient (you have to figure out where Feature is actually defined), verbose, and subject to change in future versions.
I would suggest as an alternative to simply define
import tensorflow as tf
Feature = tf.train.Feature

Resources