You don't want to pickle the predictions but rather the fit.

Change joblib.dump(nb_predict_train, "trained-model.pkl") to joblib.dump(nb_model, "trained-model.pkl")

Answer from Tophat on Stack Exchange
Discussions

python - AttributeError: 'numpy.ndarray' object has no attribute 'predict' - Data Science Stack Exchange
Data Science is part of Stack Overflow’s open communities: specialist spaces where curiosity is welcome, knowledge is shared freely, and the best answers rise to the top · Turn scattered docs and code into trusted AI context. Explore the new Stack Internal platform More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
December 14, 2017
Numpy has not attribute?
Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission: You are looping over an object using something like for x in range(len(items)): print(items[x]) This is simpler and less error prone written as for item in items: print(item) If you DO need the indexes of the items, use the enumerate function like for idx, item in enumerate(items): print(idx, item) If you think you need the indexes because you are doing this: for x in range(len(items)): print(items[x], prices[x]) Then you should be using zip: for item, price in zip(items, prices): print(item, price) More on reddit.com
🌐 r/learnpython
2
1
June 23, 2017
python - AttributeError: 'numpy.ndarray' object has no attribute 'predict' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
September 9, 2019
AttributeError: 'numpy.ndarray' object has no attribute 'predict'
AttributeError: ‘numpy.ndarray’ object has no attribute ‘predict’ Untitled4.ipynb (117.2 KB) how to solve this? More on community.deeplearning.ai
🌐 community.deeplearning.ai
2
0
March 29, 2022
🌐
Streamlit
discuss.streamlit.io › community cloud
While predict we are getting error AttributeError: 'numpy.ndarray' object has no attribute 'predict' - Community Cloud - Streamlit
April 2, 2024 - Github link : git@github.com:pawaravinash0007/MachineLearning.git streamlit deployment link : Streamlit Dear All, We are getting attribute errors AttributeError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).
🌐
Reddit
reddit.com › r/learnpython › numpy has not attribute?
r/learnpython on Reddit: Numpy has not attribute?
June 23, 2017 -

I am trying to plot a .txt file of lines of the form: filename.txt date magnitude V098550.txt 362.0 3.34717962317 but I am getting the error "numpy.float64' object has no attribute 'replace'". Does anyone know if this is a syntax error with numpy, or how I can resolve my issue?

import numpy as np
import matplotlib.pyplot as plt
x, y = np.loadtxt ("condensed.txt", usecols=(1, 2),        
delimiter=",", unpack=True)
for ii in range (len(x)): x[ii].replace('.txt', '.lc\n') jd, npmag = np.loadtxt ("/net/jovan/export/jovan/oelkerrj/Vela/rotation/Vela/"+x[ii], usecols= (1, 2), unpack=True)
    plt.scatter (jd, npmag)
    plt.xlabel ('Time')
    plt.ylabel ('Mag')
    plt.ylim ([max (npmag), min (npmag)])
    plt.show() # aftertest comment this out
    fileName = x[ii][:-3] + ".png"
    plt.savefig(fileName)

print "done"

Top answer
1 of 2
2
Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission: You are looping over an object using something like for x in range(len(items)): print(items[x]) This is simpler and less error prone written as for item in items: print(item) If you DO need the indexes of the items, use the enumerate function like for idx, item in enumerate(items): print(idx, item) If you think you need the indexes because you are doing this: for x in range(len(items)): print(items[x], prices[x]) Then you should be using zip: for item, price in zip(items, prices): print(item, price)
2 of 2
1
Numpy arrays are not the same as strings, so they don't have the normal string methods. However, there are function versions of most of the string methods you can use: x = np.replace(x, '.txt', '.lc') This had the advantage of operating on every element of the array at once, rather than having to do each one-at-a-time in a loop. So the above line would go before the loop, not inside it. To convert x[ii] to a normal string you can use the x[ii].tolist(). Despite what the name implies, tolist doesn't convert to a list for numpy scalars (which x[ii]) is, instead it converts to the appropriate native python type (so numpy ints to python integers, numpy floats to python floats, numpy strings to python strings, etc.). You can then use normal python string operations on the result.
🌐
Stack Overflow
stackoverflow.com › questions › 57847177 › attributeerror-numpy-ndarray-object-has-no-attribute-predict
python - AttributeError: 'numpy.ndarray' object has no attribute 'predict' - Stack Overflow
September 9, 2019 - print(model.predict([['Finance and Control'], ['EMEA'], ['Professional Services']])) it returned this error : AttributeError: 'numpy.ndarray' object has no attribute 'predict'
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-attributeerror-module-numpy-has-no-attribute-float-in-python
How to fix AttributeError: module numpy has no attribute float' in Python - GeeksforGeeks
July 23, 2025 - This solution ensures compatibility with recent numpy versions and avoids the "AttributeError: module 'numpy' has no attribute 'float'" error. ... Explicitly specifying Python types involves using dtype='float64' or dtype='float32' in numpy arrays instead of relying on the deprecated np.float attribute.
Find elsewhere
🌐
GitHub
github.com › scikit-learn › scikit-learn › issues › 3142
linear_model giving AttributeError: 'numpy.float64' object has no attribute 'exp' · Issue #3142 · scikit-learn/scikit-learn · GitHub
May 10, 2014 - I think that LinearClassifierMixin.decision_function is returning an array of dtype=object which makes np.exp() fail. None of the values in the array look to my eye like anything other than floats. Casting the array explicitly as a float (as the commented line shows) allows predict_proba to exponentiate.
Author: scikit-learn
🌐
FEniCS Project
fenicsproject.discourse.group › dolfin-adjoint
AttributeError: 'numpy.float64' object has no attribute 'block_variable' - dolfin-adjoint - FEniCS Project
October 19, 2023 - Hi all, I want my force to reach the values I want with the applied displacement. I determine these desired points in the polynomial. So I minimize my function to find the polynomial coefficients that will allow it to p…
🌐
DeepLearning.AI
community.deeplearning.ai › course q&a › natural language processing › nlp with classification and vector spaces
Unit test throwing error on predictions, 'float' object has no attribute 'shape' - NLP with Classification and Vector Spaces - DeepLearning.AI
January 25, 2022 - I have written my predict_tweet function, and the outputs seem to be correct: However, when I run the unit test, I get an error on the unit test itself. Obviously something is wrong on my end, something is not an a…
🌐
OpenCV
forum.opencv.org › python
'Model' object has no attribute 'predict' - Python - OpenCV
Hello, I have done the code below but i am getting an error. vs = cv2.VideoCapture(video_path) output_video_1,output_video_2 = None,None # Loop until the end of the video stream while True: # Load the image of the ground and resize it to the correct size img = cv2.imread("../img/chemin_1.png") ...
Published: August 12, 2021
🌐
Reddit
reddit.com › r/learnpython › [deleted by user]
[deleted by user] : r/learnpython
August 28, 2022 - Yup! that means you are running tokenizer on a column or data that is of the type float64 (64 bit float/number).
Top answer
1 of 9
65

The answer is already provided in the comments by @mattdmo and @tdelaney:

  • NumPy 1.20 (release notes) deprecated numpy.float, numpy.int, and similar aliases, causing them to issue a deprecation warning

  • NumPy 1.24 (release notes) removed these aliases altogether, causing an error when they are used

In many cases you can simply replace the deprecated NumPy types by the equivalent Python built-in type, e.g., numpy.float becomes a "plain" Python float.

For detailed guidelines on how to deal with various deprecated types, have a closer look at the table and guideline in the release notes for 1.20:

...

To give a clear guideline for the vast majority of cases, for the types bool, object, str (and unicode) using the plain version is shorter and clear, and generally a good replacement. For float and complex you can use float64 and complex128 if you wish to be more explicit about the precision.

For np.int a direct replacement with np.int_ or int is also good and will not change behavior, but the precision will continue to depend on the computer and operating system. If you want to be more explicit and review the current use, you have the following alternatives:

  • np.int64 or np.int32 to specify the precision exactly. This ensures that results cannot depend on the computer or operating system.
  • np.int_ or int (the default), but be aware that it depends on the computer and operating system.
  • The C types: np.cint (int), np.int_ (long), np.longlong.
  • np.intp which is 32bit on 32bit machines 64bit on 64bit machines. This can be the best type to use for indexing.

...

If you have dependencies that use the deprecated types, a quick workaround would be to roll back your NumPy version to 1.24 or less (as suggested in some of the other answers), while waiting for the dependency to catch up. Alternatively, you could create a patch yourself and open a pull request, or monkey patch the dependency in your own code.

2 of 9
39

In the 1.24 version:

The deprecation for the aliases np.object, np.bool, np.float, np.complex, np.str, and np.int is expired (introduces NumPy 1.20). Some of these will now give a FutureWarning in addition to raising an error since they will be mapped to the NumPy scalars in the future.

pip install "numpy<1.24" to work around it.

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '1.23.5'

In [3]: np.float(3)
<ipython-input-3-8262e04d58e1>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  np.float(3)
Out[3]: 3.0
🌐
GitHub
github.com › huggingface › setfit › issues › 197
[Bug] AttributeError: 'numpy.float64' object has no attribute 'pop' · Issue #197 · huggingface/setfit · GitHub
November 20, 2022 - Hi, First of all, I would like to thank you for providing this great and useful library. The following libraries are installed with Python 3.9: setfit==0.4.1 optuna==3.0.3 transformers==4.20.1 On my dataset, I wanted to run a hyperparame...
Author: huggingface
🌐
Gauthmath
gauthmath.com › study resources › others
Solved: How to fix attributeerror: module numpy has no attribute float.? [Others]
August 5, 2024 - To fix the AttributeError, ensure you're using the correct attribute or method, such as replacing numpy.float with float or numpy.float64.
🌐
GitHub
github.com › roboflow › supervision › discussions › 912
AttributeError: module 'numpy' has no attribute 'float'. · roboflow/supervision · Discussion #912 · GitHub
AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe.
Author: roboflow