Search code examples
pythontensorflowdotnetnuke

How to use predict_proba for DNNClassifier in tensorflow?


How to use predict_proba for DNNClassifier in tensorflow 1.5? I am using the code below. I believe, that the command to get the probability instead of the exact result class, may have changed as compared to previous tensorflow versions.

new_classifier = 
tf.estimator.DNNClassifier(feature_columns=feature_columns, hidden_units=
[10, 20, 10],n_classes=int(trn_classes),model_dir=os.path.dirname("Model/"))

After that, when I use predictions = list(new_classifier.predict_proba(input_fn=predict_input_fn))

I get error-

AttributeError: 'DNNClassifier' object has no attribute 'predict_proba'

Please help.


Solution

  • if your estimator is :

    new_classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns, hidden_units=[10, 20, 10],n_classes=int(trn_classes),model_dir=os.path.dirname("Model/"))

    for probabilities of each prediction try:

    y_out_prob=new_classifier.predict(input_fn=predict_input_fn,predict_keys="probabilities")
    

    i.e set predict_keys='probalities'