Skip to content

Instantly share code, notes, and snippets.

@EvanGertis
Created January 16, 2022 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanGertis/002b33aa8cfbac2ab96114099089f70e to your computer and use it in GitHub Desktop.
Save EvanGertis/002b33aa8cfbac2ab96114099089f70e to your computer and use it in GitHub Desktop.
def prob_continous_value(A, v, classAttribute, dataset, x):
# calcuate the average for all values of A in dataset with class = x
a = dataset[dataset[classAttribute] == x][A].mean()
# calculate the standard deviation for all values A in dataset with class = x
stdev = 1
stdev = dataset[dataset[classAttribute] == x][A].std()
v = dataset[A].iloc[0]
if stdev == 0.0:
stdev = 0.00000000000001
return (1/(math.sqrt(2*math.pi)*stdev))*math.exp(-((v-a)*(v-a))/(2*stdev*stdev))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment