你如何在Tensorflow预测

时间:2016-10-26 22:55:39

标签: python machine-learning neural-network tensorflow

我是张力流的菜鸟。所以我正在玩Xor问题我的问题是你如何在tensorflow中预测。因此,当我输入[1,0]时,我希望它给我1或0.另外在不同的场景中,如果它是具有多个值(回归量)的模型,例如股票。我该怎么做谢谢你。 到目前为止,我到目前为止:

const initialState = [
    {
        id: 1,
        clientFirstN‌​ame: 'Paul',
        ...otherFields
    },
    {
        id: 2,
        clientFirstN‌​ame: 'Adam',
        ...otherFields
    }
];

// Reducers
function clientSubReducer(state = initialState, action) {
    switch(action.type) {
        case 'MODIFY_CLIENT':
            return {
                ...state[action.payload.index],
                ...action.payload.fields
            }
    }
}

export function clientReducer(state, action) {
    switch(action.type) {
        case 'MODIFY_CLIENT':
            return [
                ...state.slice(0, action.payload.index),
                clientSubReducer(state, action),
                ...state.slice(action.payload.index + 1)
            ]
    }
}


//Action
function modifyClient(client) {
    return (dispatch, getStore) => {
        const store = getStore();
        let storeIndex = -1;

        for (let i = 0; i < store.clients.length; i++) {
            const storeClient = clients[i];
            if (client.id === storeClient.id) {
                storeIndex = i;
            }
        }

        // Our store contains the client object
        if (storeIndex > -1) {
            dispatch({
                action: 'MODIFY_CLIENT',
                payload: {
                    index: storeIndex,
                    fields: client // You could diff the client and store client and pass only the ones you want to modify back
                }
            })
        }
        //Our Store does not contain the client object
        else {
            dispatch({
                action: 'ADD_CLIENT',
                payload: {
                    client: client
                }
            })
        }
    }
}

1 个答案:

答案 0 :(得分:1)

由于您的分类只是0 iff输出<0.5,您可以添加新的预测节点:

prediction_op = tf.round(Output)

之后再打电话

print(sess.run(prediction_op, feed_dict={X: np.array([[1., 0.]])}))