Skip to content

Commit f8b618c

Browse files
committed
implemented naive bayes predict API
1 parent a53908d commit f8b618c

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow
6+
{
7+
public static partial class tf
8+
{
9+
public static Tensor exp(Tensor x,
10+
string name = null) => gen_math_ops.exp(x, name);
11+
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow
6+
{
7+
public static partial class tf
8+
{
9+
public static Tensor reduce_logsumexp(Tensor input_tensor,
10+
int[] axis = null,
11+
bool keepdims = false,
12+
string name = null) => math_ops.reduce_logsumexp(input_tensor, axis, keepdims, name);
13+
14+
}
15+
}

test/TensorFlowNET.Examples/NaiveBayesClassifier.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void fit(NDArray X, NDArray y)
7676
this.dist = dist;
7777
}
7878

79-
public void predict (NDArray X)
79+
public Tensor predict (NDArray X)
8080
{
8181
if (dist == null)
8282
{
@@ -96,13 +96,11 @@ public void predict (NDArray X)
9696
// posterior log probability, log P(c) + log P(x|c)
9797
var joint_likelihood = tf.add(new Tensor(priors), cond_probs);
9898
// normalize to get (log)-probabilities
99-
/*
100-
var norm_factor = tf.reduce_logsumexp(joint_likelihood, axis = 1, keep_dims = True)
99+
100+
var norm_factor = tf.reduce_logsumexp(joint_likelihood, new int[] { 1 }, true);
101101
var log_prob = joint_likelihood - norm_factor;
102102
// exp to get the actual probabilities
103-
return tf.exp(log_prob)
104-
*/
105-
throw new NotImplementedException();
103+
return tf.exp(log_prob);
106104
}
107105
}
108106
}

0 commit comments

Comments
 (0)