使用tensorflow DNNClassifier和cross_val_score的结果很差

时间:2016-08-22 13:03:16

标签: machine-learning scikit-learn tensorflow classification

我正在使用python 3.5,tensorflow 0.10及其DNNClassifier。如果我执行单个培训和测试阶段,如下所示,测试结果是不错的:准确度= 0.9333

import tensorflow as tf
from tensorflow.contrib import learn
from sklearn.cross_validation import cross_val_score, ShuffleSplit, train_test_split
from sklearn.metrics import accuracy_score
import numpy as np
from sklearn.metrics import accuracy_score
from sklearn import datasets, cross_validation

iris = datasets.load_iris()

feature_columns = learn.infer_real_valued_columns_from_input(iris.data)

x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.20, random_state = 20)

model = learn.DNNClassifier(hidden_units=[5], 
                             n_classes=3, 
                             feature_columns=feature_columns, 
                            )

model.fit(x_train, y_train, steps=1000)
predicted = model.predict(x_test)

print('Accuracy on test set: %f' % accuracy_score(y_test, predicted))

如果我使用sklearn的cross_val_score,那么最终结果会更差,约为0.33准确度:

model = learn.DNNClassifier(hidden_units=[5], 
                             n_classes=3, 
                             feature_columns=feature_columns, 
                            )

scores = cross_val_score(estimator=model, 
                         X=iris.data, 
                         y=iris.target, 
                         scoring = 'accuracy',
                         cv=5,
                         fit_params={'steps': 1000},
#                          verbose=100
                        )

print(scores)
print(np.mean(scores))

他们的平均分数是:

[ 0.          0.33333333  1.          0.33333333  0.        ]
0.333333333333

我的交叉验证估算代码出了什么问题?

0 个答案:

没有答案