繁体   English   中英

无法导入Keras库

[英]Unable to import Keras Library

我正在研究数据集上的人工神经网络算法。 以下是我正在使用的数据集的来源。

Kaggle数据集

我已经运行了代码,直到Feature Scaling为止,并且成功运行了而没有任何问题。 下面是我运行的代码:

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv("C:\Machine learning\practices\Machine Learning A-Z Template Folder\Part 8 - Deep Learning\Section 39 - Artificial Neural Networks (ANN)\Artificial-Neural-Networks\Artificial_Neural_Networks\Churn1_Modelling.csv")
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

在这之后我跑了

import keras

它给了我错误,因为Python停止工作并且每次都重新启动内核。 我已经安装了所有库和模块。 以下是我已经安装的模块:

Package                            Version
---------------------------------- -----------
alabaster                          0.7.9
anaconda-clean                     1.0
anaconda-client                    1.5.1
anaconda-navigator                 1.3.1
argcomplete                        1.0.0
astroid                            1.4.7
astropy                            1.2.1
Babel                              2.3.4
backports.shutil-get-terminal-size 1.0.0
backports.weakref                  1.0rc1
beautifulsoup4                     4.5.1
bitarray                           0.8.1
blaze                              0.10.1
bleach                             1.5.0
bokeh                              0.12.2
boto                               2.42.0
Bottleneck                         1.1.0
certifi                            2018.8.24
cffi                               1.7.0
chardet                            3.0.4
chest                              0.2.3
click                              6.6
cloudpickle                        0.2.1
clyent                             1.2.2
colorama                           0.3.7
comtypes                           1.1.2
conda                              4.5.11
conda-build                        2.0.2
configobj                          5.0.6
contextlib2                        0.5.3
cryptography                       1.5
cycler                             0.10.0
Cython                             0.24.1
cytoolz                            0.9.0.1
dask                               0.11.0
datashape                          0.5.2
decorator                          4.0.10
dill                               0.2.5
docutils                           0.12
dynd                               c328ab7
et-xmlfile                         1.0.1
fastcache                          1.0.2
filelock                           2.0.6
Flask                              0.11.1
Flask-Cors                         2.1.2
gevent                             1.1.2
greenlet                           0.4.10
h5py                               2.6.0
HeapDict                           1.0.0
html5lib                           0.9999999
idna                               2.1
imagesize                          0.7.1
ipykernel                          4.5.0
ipython                            5.1.0
ipython-genutils                   0.1.0
ipywidgets                         5.2.2
itsdangerous                       0.24
jdcal                              1.2
jedi                               0.9.0
Jinja2                             2.8
jsonschema                         2.5.1
jupyter                            1.0.0
jupyter-client                     4.4.0
jupyter-console                    5.0.0
jupyter-core                       4.2.0
Keras                              2.2.2
Keras-Applications                 1.0.4
Keras-Preprocessing                1.0.2
keyring                            13.2.1
lazy-object-proxy                  1.2.1
llvmlite                           0.13.0
locket                             0.2.0
lxml                               3.6.4
Markdown                           2.2.0
MarkupSafe                         0.23
matplotlib                         1.5.3
menuinst                           1.4.1
mistune                            0.7.3
mkl-fft                            1.0.4
mkl-random                         1.0.1
mpmath                             0.19
multipledispatch                   0.4.8
nb-anacondacloud                   1.2.0
nb-conda                           2.0.0
nb-conda-kernels                   2.0.0
nbconvert                          4.2.0
nbformat                           4.1.0
nbpresent                          3.0.2
networkx                           1.11
nltk                               3.2.1
nose                               1.3.7
notebook                           4.2.3
numba                              0.28.1
numexpr                            2.6.7
numpy                              1.15.1
numpydoc                           0.8.0
odo                                0.5.0
olefile                            0.45.1
openpyxl                           2.3.2
pandas                             0.18.1
partd                              0.3.6
path.py                            0.0.0
pathlib2                           2.1.0
patsy                              0.4.1
pep8                               1.7.0
pickleshare                        0.7.4
Pillow                             5.2.0
pip                                18.0
pkginfo                            1.3.2
ply                                3.9
prompt-toolkit                     1.0.3
protobuf                           3.6.1
psutil                             4.3.1
py                                 1.4.31
pyasn1                             0.1.9
pycodestyle                        2.4.0
pycosat                            0.6.3
pycparser                          2.14
pycrypto                           2.6.1
pycurl                             7.43.0.2
pyflakes                           1.3.0
Pygments                           2.2.0
pylint                             1.5.4
pyOpenSSL                          16.2.0
pyparsing                          2.1.4
pytest                             2.9.2
python-dateutil                    2.5.3
pytz                               2016.6.1
pywin32                            220
PyYAML                             3.12
pyzmq                              15.4.0
QtAwesome                          0.4.4
qtconsole                          4.2.1
QtPy                               1.5.0
requests                           2.14.2
rope-py3k                          0.9.4.post1
ruamel-yaml                        -VERSION
scikit-image                       0.12.3
scikit-learn                       0.19.2
scipy                              1.1.0
setuptools                         40.2.0
simplegeneric                      0.8.1
singledispatch                     3.4.0.3
six                                1.11.0
snowballstemmer                    1.2.1
sockjs-tornado                     1.0.3
sphinx                             1.4.6
spyder                             3.3.1
spyder-kernels                     0.2.4
SQLAlchemy                         1.0.13
statsmodels                        0.6.1
sympy                              1.0
tables                             3.2.2
tensorflow                         1.2.0
Theano                             1.0.2
toolz                              0.8.0
tornado                            4.4.1
traitlets                          4.3.0
unicodecsv                         0.14.1
wcwidth                            0.1.7
Werkzeug                           0.14.1
wheel                              0.31.1
widgetsnbextension                 1.2.6
win-unicode-console                0.5
wincertstore                       0.2
wrapt                              1.10.6
xlrd                               1.0.0
XlsxWriter                         0.9.3
xlwings                            0.10.0
xlwt                               1.1.2

请让我知道安装tensorflow和keras时是否出现问题,或者是否存在其他问题,因为我无法继续使用人工神经网络算法来预测值。

谢谢。

看来您正在做SuperDataScience机器学习课程。
您的代码是正确的,并且运行良好。 如果您使用的是anaconda内核(spyder IDE使用anaconda内核),请尝试通过pip3 install --upgrade tensorflow
根据您提供的库列表,您已经通过conda forge安装了tensorflow。

通过pip安装tensorflow后,尝试通过以下方法测试您的tensorflow安装:

import tensorflow as tf
    hello = tf.constant('Hello, TensorFlow!')
    sess = tf.Session()
    print(sess.run(hello))

您应该看到此输出Hello, TensorFlow!
现在,您可以尝试通过运行以下代码来检查您的keras安装: pip install keras
import keras 您应该看到以下输出: Using TensorFlow backend.

最好的祝福

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM