Keras: Cannot Import Name np_utils [duplicate]

2024/10/18 15:26:13

I'm using Python 2.7 and a Jupyter notebook to do some basic machine learning. I'm following along with this tutorial:

http://machinelearningmastery.com/regression-tutorial-keras-deep-learning-library-python/

I'm simply trying to import different things from Keras so I can run the tutorial. Specifically, I do this:

from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline

and it gets stuck at the first import, giving me a traceback of this:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-28-aae66d0fdaee> in <module>()
----> 1 from keras.models import Sequential2 from keras.layers import Dense3 from keras.wrappers.scikit_learn import KerasRegressor4 from sklearn.model_selection import cross_val_score5 from sklearn.model_selection import KFold/Users/newscred/anaconda/lib/python2.7/site-packages/keras/__init__.py in <module>()1 from __future__ import absolute_import2 
----> 3 from . import utils4 from . import activations5 from . import applications/Users/newscred/anaconda/lib/python2.7/site-packages/keras/utils/__init__.py in <module>()1 from __future__ import absolute_import
----> 2 from . import np_utils3 from . import generic_utils4 from . import data_utils5 from . import io_utilsImportError: cannot import name np_utils

I've Googled around but can't seem to find out why I'm running into this problem / how to fix. Any ideas?

Thanks!

Answer

That tutorial was written on June 9th, 2016. Keras 2 was released in March 2017. Try installing the old version, using pip install keras==1.2.2.

https://en.xdnf.cn/q/72422.html

Related Q&A

Python 3 string index lookup is O(1)?

Short story:Is Python 3 unicode string lookup O(1) or O(n)?Long story:Index lookup of a character in a C char array is constant time O(1) because we can with certainty jump to a contiguous memory loca…

Using PIL to detect a scan of a blank page

So I often run huge double-sided scan jobs on an unintelligent Canon multifunction, which leaves me with a huge folder of JPEGs. Am I insane to consider using PIL to analyze a folder of images to detec…

Pandas: Filling data for missing dates

Lets say Ive got the following table:ProdID Date Val1 Val2 Val3 Prod1 4/1/2019 1 3 4 Prod1 4/3/2019 2 3 54 Prod1 4/4/2019 3 4 54 Prod2 4/1/2019 1 3 3…

Linear Regression: How to find the distance between the points and the prediction line?

Im looking to find the distance between the points and the prediction line. Ideally I would like the results to be displayed in a new column which contains the distance, called Distance.My Imports:impo…

How to draw a Tetrahedron mesh by matplotlib?

I want to plot a tetrahedron mesh by matplotlib, and the following are a simple tetrahedron mesh: xyz = np.array([[-1,-1,-1],[ 1,-1,-1], [ 1, 1,-1],[-1, 1,-1],[-1,-1, 1],[ 1,-1, 1], [ 1, 1, 1],[-1, 1, …

How to set seaborn jointplot axis to log scale

How to set axis to logarithmic scale in a seaborn jointplot? I cant find any log arguments in seaborn.jointplot Notebook import seaborn as sns import pandas as pddf = pd.read_csv("https://storage…

Convert decision tree directly to png [duplicate]

This question already has answers here:graph.write_pdf("iris.pdf") AttributeError: list object has no attribute write_pdf(10 answers)Closed 7 years ago.I am trying to generate a decision tree…

Python: can I modify a Tuple?

I have a 2 D tuple (Actually I thought, it was a list.. but the error says its a tuple) But anyways.. The tuple is of form: (floatnumber_val, prod_id) now I have a dictionary which contains key-> p…

Saving scatterplot animations

Ive been trying to save an animated scatterplot with matplotlib, and I would prefer that it didnt require totally different code for viewing as an animated figure and for saving a copy. The figure show…

Pandas: Bin dates into 30 minute intervals and calculate averages

I have a Pandas dataframe with two columns which are speed and time.speed date 54.72 1:33:56 49.37 1:33:59 37.03 1:34:03 24.02 7:39:58 28.02 7:40:01 24.04 7:40:04 24.02 7:40:07 25.35 …