Reputation: 1079
I just installed skflow and TensorFlow and I'm having a problem with the example that comes with skflow. The example code is:
import random
import pandas
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.cross_validation import train_test_split
import tensorflow as tf
import skflow
data = pandas.read_csv('tf_examples/data/titanic_train.csv')
# Use SciKit Learn
y, X = data['Survived'], data[['Age', 'SibSp', 'Fare']].fillna(0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
lr = LogisticRegression()
lr.fit(X_train, y_train)
print accuracy_score(lr.predict(X_test), y_test)
# 3 layer neural network with rectified linear activation.
random.seed(42)
classifier = skflow.TensorFlowDNNClassifier(hidden_units=[10, 20, 10],
n_classes=2, batch_size=128, steps=500,
learning_rate=0.05)
classifier.fit(X_train, y_train)
print accuracy_score(classifier.predict(X_test), y_test)
When I run this example, I get:
python Example1.py
0.664804469274
Traceback (most recent call last):
File "Example1.py", line 27, in <module>
classifier.fit(X_train, y_train)
File "//anaconda/lib/python2.7/site-packages/skflow/__init__.py", line 119, in fit
self._setup_data_feeder(X, y)
File "//anaconda/lib/python2.7/site-packages/skflow/__init__.py", line 71, in _setup_data_feeder
self.n_classes, self.batch_size)
File "//anaconda/lib/python2.7/site-packages/skflow/data_feeder.py", line 61, in __init__
x_dtype = np.int64 if X.dtype == np.int64 else np.float32
File "//anaconda/lib/python2.7/site-packages/pandas/core/generic.py", line 2246, in __getattr__
(type(self).__name__, name))
AttributeError: 'DataFrame' object has no attribute 'dtype'
The failure occurs on:
classifier.fit(X_train, y_train)
Any help will be greatly appreciated.
Upvotes: 3
Views: 951
Reputation: 41
I think this is an issue with the interface between skflow and pandas. Try calling .values
on the data frames before passing them to skflow:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
lr = LogisticRegression()
lr.fit(X_train.values, y_train.values)
print accuracy_score(lr.predict(X_test.values), y_test.values)
# 3 layer neural network with rectified linear activation.
random.seed(42)
classifier = skflow.TensorFlowDNNClassifier(hidden_units=[10, 20, 10],
n_classes=2, batch_size=128, steps=500,
learning_rate=0.05)
classifier.fit(X_train.values, y_train.values)
print accuracy_score(classifier.predict(X_test.values), y_test.values)
Upvotes: 4
Reputation: 696
thanks for using skflow! We've added pandas support long time ago. You can find the specific implementation io/pandas_io.py in skflow:
More of our examples now use pandas to load the data, for example, the text classification examples, like this one:
Hope this helps and happy using skflow!
Upvotes: 0