Vacassal Alsk
Vacassal Alsk

Reputation: 513

Why tensor flow could not load csv

I just installed tensor flow using pip and I try to run the following tutorial:

https://www.tensorflow.org/versions/r0.11/tutorials/tflearn/index.html

# Data sets
IRIS_TRAINING = "iris_training.csv"
IRIS_TEST = "iris_test.csv"

# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING,
                                                       target_dtype=np.int)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TEST,
                                                   target_dtype=np.int)

But I have error:

    training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING,
AttributeError: 'module' object has no attribute 'load_csv'

I read some answer saying that I need to use pandas dataframe? But shouldn't everything just works as in the tutorial? That is so strange! I should not be the only one facing this issue right?

Here's the whole code as in the tutorial:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import numpy as np

# Data sets
IRIS_TRAINING = "iris_training.csv"
IRIS_TEST = "iris_test.csv"

# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING,
                                                       target_dtype=np.int)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TEST,
                                                   target_dtype=np.int)

# Specify that all features have real-value data
feature_columns = [tf.contrib.layers.real_valued_column("", dimension=4)]

# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
                                            hidden_units=[10, 20, 10],
                                            n_classes=3,
                                            model_dir="/tmp/iris_model")

# Fit model.
classifier.fit(x=training_set.data,
               y=training_set.target,
               steps=2000)

# Evaluate accuracy.
accuracy_score = classifier.evaluate(x=test_set.data,
                                     y=test_set.target)["accuracy"]
print('Accuracy: {0:f}'.format(accuracy_score))

# Classify two new flower samples.
new_samples = np.array(
    [[6.4, 3.2, 4.5, 1.5], [5.8, 3.1, 5.0, 1.7]], dtype=float)
y = classifier.predict(new_samples)
print('Predictions: {}'.format(str(y)))

Upvotes: 0

Views: 1368

Answers (3)

skyfacon
skyfacon

Reputation: 11

The library urllib have removed the method urlopen(), you should import urllib.request, then use the method urllib.request.urlopen().

Upvotes: 0

mrry
mrry

Reputation: 126154

The function tf.contrib.learn.datasets.base.load_csv() was removed in TensorFlow release 0.11. Depending on whether the file has a header or not (and the Iris dataset does have a header), the replacement functions are:

Upvotes: 1

Vacassal Alsk
Vacassal Alsk

Reputation: 513

since my version is 11... They removed load_csv in 11 without changing the tutorial... I have to run version 0.10.0rc0 just to run the tutorial.

Upvotes: 0

Related Questions