Created
April 24, 2021 14:31
-
-
Save shubham0204/dc3ddb7d703582a6cec781b4af46f355 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class to implement Gaussian Naive Bayes | |
class GaussianNB( private var dataFrame : DataFrame ) { | |
// Array to store Gaussian Distributions for each feature. | |
private var featureDistributions : Array<GaussianDistribution> | |
// Prior probabilities stored in a HashMap of form ( column_name , prior_prob ) | |
private var priorProbabilities : HashMap<String,Float> | |
private var resultCallback : ResultCallback? = null | |
init { | |
// Construct Gaussian Distributions for each feature and append them to `featureDistributions`. | |
val GDs = ArrayList<GaussianDistribution>() | |
for ( featureColumn in dataFrame.featureColumns ) { | |
GDs.add( GaussianDistribution( featureColumn.featureMean , featureColumn.featureStdDev )) | |
} | |
featureDistributions = GDs.toTypedArray() | |
// Compute prior probabilities and store them in `priorProbabilities`. | |
priorProbabilities = computePriorProbabilities( dataFrame.labels ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment