Not able to find out the version of a module - python-3.x

I have imported norm as:
from scipy.stats import norm
I want to find out the version using:
print(scipy.__version__)
but it is raising an error called:
NameError: name 'scipy' is not defined
if i am using this:
print(norm.__version__)
but it is raising another error called:
AttributeError: 'norm_gen' object has no attribute '__version__'
Please help me to solve this issue.
Thanks

The line from scipy.stats import norm doesn't make the name scipy available in your current namespace. To use scipy.__version__, you must first import scipy.
In [57]: import scipy
In [58]: print(scipy.__version__)
1.4.1

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?

AttributeError: module 'sklearn.metrics' has no attribute 'items'

Here is my code..
import imp
from sklearn.metrics import classification_report
from sklearn import metrics
from sklearn.metrics import accuracy_score
for title, metric in metrics.items():
print(title, metric(labels_categorical_dev.argmax(axis=1), y_pred.argmax(axis=1)))
print(classification_report(labels_categorical_dev.argmax(axis=1), y_pred.argmax(axis=1)))
y_pred = model.predict([message_first_message_test, message_second_message_test, message_third_message_test])
Iam getting below error..
Traceback (most recent call last):
File "getopt.py", line 6, in
for title, metric in metrics.items():
AttributeError: module 'sklearn.metrics' has no attribute 'items'
I have tried with versions from scikit-learn=0.20.0 to scikit-learn=0.24.2
But still getting this error. Please give me a solution for this.
Can you share more details about what is the purpose of your code? As you can see here, there isn't any attribute of sklearn.metrics named items().
.items() is used for dictionaries in order to get the values pertaining to different keys in that dictionary.
Also, you have defined y_pred after it has been referenced, so that will cause an error as well.

ImportError: cannot import name 'PCA' from 'matplotlib.mlab'

According to this task:
Principal Component Analysis (PCA) in Python
I included this line
import from matplotlib.mlab import PCA
but I get the error message:
cannot import name 'PCA' from 'matplotlib.mlab'
I'm using Python3.7 and I have no idea how I can use the PCA function from matlab. Is the new version of matplotlib depricated or is PCA included to another library?
I really don't know if it is too late to reply now. But I will just place it here anyways.
import numpy as np
from sklearn.decomposition import PCA

matplotlib.pyplot plot_date function breaks on cftime.datetime objects

Trying to plot data using the matplotlib.pyplot.plot_date function with datetime objects originating from the netCDF4.num2date function I get the following error:
In [1]: from netCDF4 import num2date
In [2]: from matplotlib.pyplot import plot_date
In [3]: d=num2date((86400,2*86400),"seconds since 2000-01-01")
In [4]: gca().plot_date(d,(0,1))
...
AttributeError: 'cftime._cftime.DatetimeGregorian' object has no attribute 'toordinal'
The above exception was the direct cause of the following exception:
ConversionError
...
ConversionError: Failed to convert value(s) to axis units: array([cftime.DatetimeGregorian(2000-01-02 00:00:00),
cftime.DatetimeGregorian(2000-01-03 00:00:00)], dtype=object)
The following package versions are installed:
pandas 1.0.3
matplotlib 3.2.1
netcdf4 1.5.1.2
cftime 1.1.1.2
As the same thing perfectly works on a different machine with older package versions, I assume a version issue.
Also, I've tried the solution suggested in this thread and other related threads which seemed like a similar issue, but
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
didn't help neither.
Any suggestions welcome;)
Found the answer myself, from version 1.1.0 the num2date function in the cftime package changed its default behaviour to return cftime datetime instances instead of python datetime instances where possible (the option argument only_use_cftime_datetimes is now True by default, instead of False). The plot_date function however, at least currently, doesn't handle these.
To avoid the issue, use the arguments only_use_cftime_dateimes=False and only_use_python_datetime=True or use the convenience function num2pydate.

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