Reputation: 149
I am using scikit-learn for evaluating my neural net implemented in tensorFlow and wrapped by an TensorFlow estimator:
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 results in following error:
TypeError: If no scoring is specified, the estimator passed should have a 'score' method. The estimator 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) does not.
When i define a scoring method like shown here:
from sklearn import metrics
cross_val_score(classifier, data, y=labels, cv=10,scoring=metrics.f1_score)
following error occurs:
scoring value looks like it is a metric function rather than a scorer. A scorer should require an estimator as its first parameter. Please use
make_scorer
to convert a metric to a scorer.
When i use make_scorer like shown here:
cross_val_score(classifier, data, y=labels, cv=10,scoring=metrics.make_scorer(metrics.accuracy_score))
following error occurs:
new_object = klass(**new_object_params) TypeError: init() got an unexpected keyword argument 'params'
Any idea?
Upvotes: 2
Views: 423