기본 콘텐츠로 건너뛰기

라벨이 sample인 게시물 표시

[matplotlib]quiver()함수

통계관련 그래프

다음 그래프들은 전자책 파이썬과 함께하는 통계이야기 4 장에 수록된 그림들의 코드들입니다. import numpy as np import pandas as pd from scipy import stats from sklearn.preprocessing import StandardScaler import FinanceDataReader as fdr import yfinance as yf import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") #fig 421 st=pd.Timestamp(2022,12, 1) et=pd.Timestamp(2023, 4, 1) da=fdr.DataReader("KS11", st, et) pop=(da['Close']-da['Open'])/da['Open']*100 np.random.seed(1) xBar=np.array([]) for i in range(20): x=pop.sample(5, random_state=i) xBar=np.append(xBar, x.mean()) xBar2=np.array([]) for i in range(100): x=pop.sample(5, random_state=i) xBar2=np.append(xBar2, x.mean()) fig, ax=plt.subplots(1, 2, figsize=(8, 3)) ax[0].hist(xBar, 10, rwidth=0.8, color="blue", label="n=20") ax[0].axvline(xBar.mean(), 0, 0.9, color="red", label=f"m={round(xBar.mean(), 2)}") ax[0].set_xlabel("x", weight=...

[numpy]랜덤수 생성을 위한 numpy 함수들

랜덤수 생성을 위한 numpy 함수들 numpy 라이브러리의 random 클래스하에서 랜덤수를 생성하는 다양한 함수를 제공합니다. 이 결과 역시 배열 객체입니다. random 함수들 r: 행의 수, c: 열의 수 [a, b) = a≤ x < b 함수 내용 np.random.rand(r, c) [0, 1) 사이의 균일 분포를 따르는 랜덤수 생성 지정한 차원(행×열)의 배열객체를 반환 양의 정수 입력으로 1차원 랜덤 벡터 생성 np.random.randn(r,c) 표준정규분포에 부합하는 랜덤수 생성 지정한 차원(행×열)의 배열객체를 반환 양의 정수 입력으로 1차원 랜덤 벡터 생성 np.random.sample((r,c)) [0, 1)지정한 크기(차원)의 랜덤수를 생성 위의 함수들과 달리 인수를 튜플 형식으로 전달 지정한 차원(행×열)의 배열객체를 반환 양의 정수 입력으로 1차원 랜덤 벡터 생성 np.random.randint(s, e, (r,c)) [s, e)의 범위의 정수들을 대상으로 랜덤수를 생성 start: 시작 수, end:마지막 수로 모두 정수 지정한 차원(행×열)의 배열객체를 반환 양의 정수 입력으로 1차원 랜덤 벡터 생성 다음 코드는 rand(), randn() 함수를 사용하여 생성한 각각 1차원 벡터와 그 객체의 분포를 작성하였습니다. import numpy as np from numpy import random import matplotlib.pyplot as plt plt.rcParams['font.family'] ='NanumGothic' random.seed(2) x=random.rand(1000) print(x[:3], x.shape) [0.4359949 0.02592623 0.54966248] (1000,) plt.figure(figsize=(3,2)) plt.hist(x, bins=10, rwidth=0.6, density=True) plt.xla...