即使在安装了tensorflow软件包后也出现“未解决的参考'tensorflow'”错误

时间:2019-12-01 08:20:54

标签: python tensorflow machine-learning

我正在通过在YouTube上关注Google的机器学习食谱视频来学习机器学习。我正在使用PyCharm和Anaconda。目前,在观看此视频时,我遇到了一个问题:

https://www.youtube.com/watch?v=cSKfRcEDGUs&list=PLOU2XLYxmsIIuiBfYad6rFYQU_jL2ryal&index=6

我已经使用以下命令安装了tensorflow:

pip install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl

但是,仍然出现Unresolved reference 'tensorflow'错误。这是我的代码:

from sklearn import metrics, model_selection
from tensorflow as tf
from tensorflow.contrib impor learn


def main(unused_argv):
    #load dataset.
    iris = learn.datasets.load_dataset('iris')
    x_train, x_test, y_train, y_test = model_selection.train_test_split(
        iris.data, iris.target, test_size = 0.2, random_stage=42)

    #Build 3 layer DNN with 10, 20, 10 units respectively
    classifier = learn.DNNCClassifier(hidden_units=[10,20,10], n_classes=3)

    #Fit and predict.
    classifier.fit(x_train, y_train, steps = 200)
    score = metrics.accuracy_score(y_test, classifier.predict(x_test))
    print('Accuracy: {0:f}'.format(score))

我应该如何解决该问题?

0 个答案:

没有答案