전체 글 (55) 썸네일형 리스트형 [Python] 평균과 기댓값 구현 python에서 평균은 numpy의 average() 함수로 구현할 수 있다. [In] # 평균 import numpy as np x = np.array([55, 45, 60, 40]) # 평균을 취할 데이터 print(np.sum(x)/4) print(np.average(x)) [Out] 50.0 50.0 python에서 기댓값은 numpy의 sum() 함수로 구현할 수 있다. 예제 1 [In] # 기댓값 import numpy as np p = np.array([0.8, 0.15, 0.05]) # 확률 x = np.array([100, 500, 1000]) # 값 print(np.sum(p*x)) # 기댓값 [Out] 205.0 예제 2 [In] # 기댓값 import numpy as np p = n.. [Python] 확률의 개념 예제 1 [In] # 확률로의 수렴 # 주사위를 던졌을 때, 5가 나오는 사건의 확률 # np.random.randint(n) : 0 ~ n-1 사이의 정수 반환 %matplotlib inline import numpy as np import matplotlib.pyplot as plt x = [] y = [] total = 0 # 시행 수 num_5 = 0 # 5가 나온 횟수 n = 5000 # 주사위를 던진 횟수 for i in range(n): if np.random.randint(6) + 1 == 5: num_5 += 1 total += 1 x.append(i) y.append(num_5 / total) plt.plot(x, y) plt.plot(x, [1/6] * n, linestyle = 'd.. [Python] 경사하강법 구현 [In] # 경사하강법 구하기 %matplotlib inline import matplotlib.pyplot as plt import numpy as np def my_func(x): # 최솟값을 구하는 함수 return x**2 - 2*x def grad_func(x): # 도함수 return 2*x - 2 lr = 0.1 # 학습계수 x = 4.0 # 초깃값 설정 record_x = [] record_y = [] for i in range(20): # x를 20번 갱신 y = my_func(x) record_x.append(x) record_y.append(y) x -= lr * grad_func(x) # 경사하강법 x_f = np.linspace(-2, 4, 1000) y_f = my_func(x_.. [DeepLearning] StarGAN 모델 리뷰 [DeepLearning] CycleGAN 모델 리뷰 [DeepLearning] GAN(Generative Adversarial NetWork) 모델 리뷰 [Python] 다변수 합성함수의 연쇄법칙 [Python] 편미분과 전미분 이전 1 2 3 4 5 6 7 다음