我正在使用scikit-learn来评估我在tensorFlow中实现并由TensorFlow估算器包装的神经网络:
import tensorflow.contrib.learn as skflow
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
...
def my_model(X,y):
...
...
return skflow.models.logistic_regression(h_drop, y)
def main():
X_train, X_test, y_train, y_test = train_test_split(data,labels,test_size=0.1, random_state=3)`
classifier = skflow.TensorFlowEstimator(model_fn=my_model, n_classes=2,batch_size=64,steps=5,optimizer='Adam',learning_rate=1e-4)
classifier.fit(X_train, y_train)
cross_val_score(classifier, data, y=labels, cv=10)
cross_val_score 会导致以下错误:
TypeError:如果未指定评分,则通过的估算工具应该得分为'方法。估计器TensorFlowEstimator(steps = 5,batch_size = 64,continue_training = False,verbose = 1,n_classes = 2,learning_rate = 0.0001,clip_gradients = 5.0,class_weight = None,params = None,optimizer = Adam)不会。
当我定义如下所示的评分方法时:
from sklearn import metrics
cross_val_score(classifier, data, y=labels, cv=10,scoring=metrics.f1_score)
发生以下错误:
得分值看起来像是一个度量函数而不是一个得分手。记分员应该要求估算器作为其第一个参数。请使用
make_scorer
将指标转换为记分员。
当我使用 make_scorer 时,如下所示:
cross_val_score(classifier, data, y=labels, cv=10,scoring=metrics.make_scorer(metrics.accuracy_score))
发生以下错误:
new_object = klass(** new_object_params) TypeError: init ()得到了一个意外的关键字参数' params'
有什么想法吗?