t-test, One Sample T-test 양측검정과 단측검정
·
Python/통계
단측검정 귀무가설 : 모평균(130g)과 표본평균(128.451g)은 같다 대립가설 : 모평균(130g)은 표본평균(128.451g)보다 작다 1. 표본 평균을 구함 1) 무게를 배열로 가져온다 np의 array는 수치계산에 강점을 지닌 다차원 배열! df = pd.read_csv('data/ch11_potato.csv') sample = np.array(df['무게']) sample 2) 표본평균을 구한다 s_mean = np.mean(sample) s_mean 2. 임계값 구함 1) 확률 변수 구함 (* 확률변수는 확률적인 변수로 보는 것, 확률을 가지는 변수) 모분산이 9임을 알고 있다고 전제 , 표본은 14개 nor..
통계 개념 정리
·
Python/통계
1. 파생변수 vs 요약변수 - 요약변수 : 수집된 데이터의 요약 ex ) 최근 1개월 삼품 구매 건수, 상품별 구매 횟수 등 .. - 파생변수 : 주관적인 의미의 변수 (논리적 타당성을 갖출 필요가 있음) ex ) 비만의 정도 (키와 몸무게 수집 후, 두 값을 활용하여 체지량 지수라는 새로운 변수를 만들어 냄) 2. 변수의 구간화 각 변수들을 구간화하여 점수를 적용하는 방식 ( ex. 소득 구간이 다양할 때, 구간을 정해 다시 소득 구간을 정하는것 ) - Binning : 연속형 변수를 범주형 변수로 구간화 하는데 쓰는 방법 ex) 신용점수 100~90점은 A, 신용점수 90~80점은 B ..) - 의사결정나무 : 의사결정나무 모형을 통해 연속형 변수를 범주형 변수로 변환하는 법 (쉽게 말하면 여러번의..
Python - plotly Graph Objects & Plotly Express로 바그래프 만들어보기
·
Python/데이터 시각화
plotly에는 Graph Objects & Plotly Express가 있음 Graph Objects로 바그래프 만들어보기 import plotly.graph_objects as go # 데이터 불러오기 y = [3, 10, 6] #fig = go.Figure() 함수로 기본 그래프 생성 fig = go.figure( # 데이터 입력 data = [go.Bar(y=y)] ) fig.show() Plotly Express로 바그래프 만들어보기 import plotly.express as px y = [3, 10, 6] # px.bar() 함수를 활용해서 bar chart 생성과 동시에 Data, Layout 값 입력 fig = px.bar(y=y) fig.show()
Python - [시각화] regplot, histplot, boxplot, swarmplot, countplot
·
Python/데이터 시각화
1. regplot : 회귀 그래프fit_reg = True : 회귀선 표시 fit_reg = False : 회귀선 표시 x   fig, ax=plt.subplots(1, 2, figsize=(15, 5))sns.regplot(x="total_bill", y="tip", data=tips, ax=ax[0], fit_reg=True)ax[0].set_title('with linear regression line')sns.regplot(x="total_bill", y="tip", data=tips, ax=ax[1], fit_reg=False)ax[1].set_title('without linear regression line')plt.show() 2. histplot : 히스토그램* 막대그래프 vs 히스토그..
Python - [시각화] scatterplot & 다중차트 그리기 & 그래프 이미지 저장
·
Python/데이터 시각화
sns.scatterplot(x = 'x축 칼럼', y= 'y축 칼럼' , hue = '기준', ax = , data = 기준데이터 ) plt.savefig(저장경로/파일이름) : 그래프 이미지 저장 import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import numpy as np tips = sns.load_dataset('tips') fig, ax = plt.subplots() ax.plot([1, 2, 3, 4, 5, 6]) # matplotlib 시각화 sns.scatterplot(x = 'total_bill', y= 'tip', hue = 'sex', ax = ax, data = tips) #seaborn 시각화..
Python - Pandas excel 파일 입출력 및 데이터 불러오기
·
Python/Python 기초문법
파일 불러오기 & 파일 저장하기 파일 불러올 때, 인코딩 확인 !! df1 = pd.read_csv('data/sea_rain1_from_notepad.csv', encoding='cp949') #UTF8 df1.to_excel("data/output.xlsx") 엑셀 파일에서 특정 시트 데이터 가져오는 법 df = pd.read_excel('data/학생시험성적.xlsx', sheet_name = '2차시험', index_col = '학생') df 엑셀 파일에서 특정 열만 가져오는 법 air_quality_pm25 = pd.read_csv("air_quality_pm25_long.csv") air_quality_pm25 = air_quality_pm25[["date.utc", "location", "p..
Python - Pandas 데이터 통합하기 (concat, join, merge)
·
Python/Python 기초문법
concat() : 행 추가 * pandas 1.4.0 버전 이후로 append 지원 안함. concat() 사용 권장 import pandas as pd import numpy as np df1 = pd.DataFrame({ 'Class1' : [95, 92, 98, 100], 'Class2' : [91, 93, 97, 99] }) df2 = pd.DataFrame({ 'Class1' : [87, 89], 'Class2' :[85, 90] }) result = pd.concat([df1, df2]) result 위 데이터에서 인덱스 정렬하고 싶을 때, ignore_index=True 추가 df3 = pd.DataFrame({ 'Class1' : [96, 83] }) pd.concat([result, d..
Python - [시각화] Maplotlib Pyplot 모듈 활용 그래프 그리기 (plot / bar)
·
Python/데이터 시각화
fig, ax = plt.subplots(nrows= m, ncols= n, figsize=(6, 3)) fig = 데이터가 담기는 프레임 (액자 같은 것) ax = 데이터가 그려지는 캔버스 m개의 행과 n열로 이루어지고, 규격 사이즈가 6, 3인 그래프 (괄호 부분은 생략 가능함) ax.plot() : 선 그래프 ax.bar() : 막대 그래프 ax.legend(loc = '범례 위치') : 범례 선 그래프 그리기 import matplotlib.pyplot as plt data1 = [10, 14, 19, 20, 25] fig, ax = plt.subplots() ax.plot(data1) plt.show() x축이 두개 이상인 그래프 import matplotlib.pyplot as plt date..