AttributeError: 'RandomOverSampler' object has no attribute 'fit_sample' - python

I am trying to use RandomOverSampler from imblearn but I'm getting error.
Looking at other posts, there seems to be a problem with older versions, but I checked my versions and I have:
sklearn.__version__
'0.24.1'
imblearn.__version__
'0.8.0'
This is the code I'm trying to run:
from imblearn.over_sampling import RandomOverSampler
OS = RandomOverSampler(sampling_strategy='auto', random_state=0)
osx, osy = OS.fit_sample(X, y)
And the error I get is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-a080b92fc7bc> in <module>
2
3 OS = RandomOverSampler(sampling_strategy='auto', random_state=0)
----> 4 osx, osy = OS.fit_sample(X, y)
AttributeError: 'RandomOverSampler' object has no attribute 'fit_sample'

You want OS.fit_resample(X, y), not fit_sample.

You want OS.fit_resample(X, y), not fit_resample.

Related

module 'keras.utils.generic_utils' has no attribute 'get_custom_objects' when importing segmentation_models

I am working on google colab with the segmentation_models library. It worked perfectly the first week using it, but now it seems that I can't import the library anymore. Here is the error message, when I execute import segmentation_models as sm :
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-6f48ce46383f> in <module>
1 import tensorflow as tf
----> 2 import segmentation_models as sm
3 frames
/usr/local/lib/python3.8/dist-packages/efficientnet/__init__.py in init_keras_custom_objects()
69 }
70
---> 71 keras.utils.generic_utils.get_custom_objects().update(custom_objects)
72
73
AttributeError: module 'keras.utils.generic_utils' has no attribute 'get_custom_objects'
Colab uses tensorflow version 2.11.0.
I did not find any information about this particular error message. Does anyone know where the problem may come from ?
Encountered the same issue sometimes. How I solved it:
open the file keras.py, change all the 'init_keras_custom_objects' to 'init_tfkeras_custom_objects'.
the location of the keras.py is in the error message. In your case, it should be in /usr/local/lib/python3.8/dist-packages/efficientnet/

I don't know why request.compile() dosen't work

I don't have any files named re or requests in my source code directory.
The function 're.compile()' worked well a few days ago, but suddenly this error happens.
import requests as re
p = re.compile('[a-z]+')
m = p.search("python")
print(m)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_7864\2076162965.py in <module>
1 import requests as re
----> 2 p = re.compile('[a-z]+')
3 m = p.search("python")
4 print(m)
AttributeError: module 'requests' has no attribute 'compile'
So i deleted and reinstall requests library and checked how this code works, but same error happens.

neuropy problem having module not callable type error

I wrote this simple program after my installation in my anaconda3 jupyter:
from NeuroPy import NeuroPy
from time import sleep
neuropy = NeuroPy()
neuropy.start()
while True:
if neuropy.meditation > 70: # Access data through object
neuropy.stop()
sleep(0.2) # Don't eat the CPU cycles
But its giving this type error:
TypeError Traceback (most recent call
last) in ()
2 from time import sleep
3
----> 4 neuropy = NeuroPy()
5 neuropy.start()
6
TypeError: 'module' object is not callable
please help me out.
This is because both the function and class is named NeuroPy. I face similar problem with this.
Try neuropy = NeuroPy.NeuroPy()

No module named 'sknn'

I am facing a problem with the sci kit neural network (sknn) module.
The code:
from sknn.mlp import Regressor, Layer
capasinicio = TodasEstaciones.loc['2015-01-12':'2015-03-31'].as_matrix()[:,[0,2]]
capasalida = TodasEstaciones.loc['2015-01-12':'2015-03-31'].as_matrix()[:,1]
neurones = 1000
tasaaprendizaje = 0.00001
numiteraciones = 9000
#Definition of the training for the neural network
redneural = Regressor(
layers=[
Layer("ExpLin", units=neurones),
Layer("ExpLin", units=neurones), Layer("Linear")],
learning_rate=tasaaprendizaje,
n_iter=numiteraciones)
redneural.fit(capasinicio, capasalida)
#Get the prediction for the train set
valortest = ([])
for i in range(capasinicio.shape[0]):
prediccion = redneural.predict(np.array([capasinicio[i,:].tolist()]))
valortest.append(prediccion[0][0])
The error message:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-7-e1e3c4d6d246> in <module>()
----> 1 from sknn.mlp import Regressor, Layer
2
3 capasinicio = TodasEstaciones.loc['2015-01-12':'2015-03-31'].as_matrix()[:,[0,2]]
4 capasalida = TodasEstaciones.loc['2015-01-12':'2015-03-31'].as_matrix()[:,1]
5 neurones = 1000
ModuleNotFoundError: No module named 'sknn'
It appears that installing the module through pip
pip install scikit-neuralnetwork
does not solve the problem
any help would be appreciated :)
what worked for me: I uninstalled both python and anaconda, then reinstalled anaconda while specifying that its corresponding PATH gets the priority when calling modules (an option that is not recommended by the developers).

tzwhere (pytzwhere) - Python 2.7 with simple test case

I'm running the simplest possible test problem that is given with the pytzwhere package. The module imports, but I'm getting an error. pytzwhere seems like a good offline option for getting timezones from GPS coordinates, but there isn't much documentation. Any help on how to reconcile this is appreciated!
In [94]:
import tzwhere
w = tzwhere()
print w.tzNameAt(1.352083, 103.819836)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-94-0b50c8083e93> in <module>()
1 import tzwhere
2
----> 3 w = tzwhere()
4 print w.tzNameAt(1.352083, 103.819836)
TypeError: 'module' object is not callable
Edit:
This has been resolved with the following code modification per the comments below -
In [108]:
from tzwhere import tzwhere
w = tzwhere.tzwhere()
print w.tzNameAt(1.352083, 103.819836)
-----------------------------------------------------------------------------
Reading json input file: /Users/user/anaconda/lib/python2.7/site-packages/tzwhere/tz_world_compact.json
Asia/Singapore
You cannot just instantiave w from module like w = tzwhere(). tzwhere is a module containing class tzwhere. As Python correctly noted, module is not callable.
from tzwhere import tzwhere
w = tzwhere()
First line imports class tzwhere from module tzwhere.
Edit: If you do import "my way" :-) w = tzwhere() is valid creation of w as instance of class tzwhere.
Usually in Python, class would be named TzWhere, which would avoid such confusion.
I assume you are trying to use https://github.com/pegler/pytzwhere/blob/master/tzwhere/tzwhere.py

Categories