2017-10-12 60 views

回答

0

我实际上已经找到了一个方法,这是非常简单的,因为我认为。我在想,有些人可能会有类似的问题,所以在这里。 Tensorflow是一种适用于机器学习模型的新框架,但我最终意识到这非常简单。

Tensorflow对你与TF创建的模型中,这* .predict(...)函数返回的预测变量定义你的模型包含“类”和“概率”

您的手机型号对于一个例子:

some_classifier = tf.estimator.Estimator(model_fn=model_fn, 
    model_dir=...) 

您可以预测做到这一点(因为我们知道它)

prediction_input_fn = tf.estimator.inputs.numpy_input_fn(
    x={"x": test_feats}, #given you have this variable containing the test data 
    y=test_labels, #and the equivalent label for the test data 
    num_epochs=1, 
    shuffle=False) 
prediction_results = some_classifier.predict(input_fn=prediction_input_fn) 

,然后变量prediction_r esults包含预测类和值的概率,然后可以保存(例如,使用熊猫)

save = panda.DataFrame(list(prediction_results)) 
save.to_csv("file.csv") 

上面的代码剪断效果很好给你已经写了代码模型内的容器的预测,如下面:

predictions = { 
    "classes": tf.argmax(input=logits, axis=1), 
    "probabilities": tf.nn.softmax(logits, name="softmax_tensor") 

}