Created
October 26, 2017 09:48
-
-
Save sencagri/919fb15bb6d01a38583ad5ac9a604d9d to your computer and use it in GitHub Desktop.
Pattern Recognition P1 Q2
This file contains 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
import numpy as np | |
# deviance ve mean buradan giriliyor | |
dev = 10 | |
var = dev ** 2 | |
mean = 3 | |
# örnek kümesinin boyutu | |
size = 150 | |
nor_dis = np.random.normal(mean, dev, size) | |
mean_c = 0 | |
for item in nor_dis: | |
mean_c+=item | |
mean_c = mean_c / size | |
var_c = 0 | |
for item in nor_dis: | |
var_c += (item - mean_c) ** 2 | |
var_c = var_c / (size - 1) | |
# girilen değerleri yazdır | |
print("prompt mean %s" %mean) | |
print("prompt var %s" %var) | |
print() | |
# standart hesaplama yöntemleri ile hesaplanan değerleri yazdır | |
print("calc mean %s" %mean_c) | |
print("calc var %s" %var_c) | |
# numpy kütüphanesini kullanarak karşılaştırma amaçlı mean ve varyans hesabı yap | |
lib_mean = np.mean(nor_dis) | |
lib_var = np.var(nor_dis) | |
print("lib calc mean %s" %lib_mean) | |
print("lib calc var %s" %lib_var) | |
print() | |
# prior bilgisini buradan giriyoruz | |
prior = 3 | |
bayes_mean = 0 | |
sov = size / var | |
oovo = 1 / var_c | |
bayes_mean = (mean_c * sov / (sov + oovo)) + (oovo * prior / (sov + oovo)) | |
# bayes estimator sonucunda bulunan mean değerini ekranda göster | |
print(); | |
print("bayes mean %s" %bayes_mean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment