#EDA는 전처리가 아니라 '탐험점 데이터 분석과정'으로 '분석'이다.
*Goals of EDA : 데이터 활용 훌륭한 모델링
*Speparator : 비교적 단순한 파일로 호환되지 않는 포맷 사용 프로그램끼리 자료 전달 시 사용
*Histogram Explained: 막대 그래프는 범주형 데이터, 간격이 없는 데이터로 누락이 있을 수 있음, 클래스의 크기, 너비의 일정함
ㄴ[ : include / ) not include
ㄴ데이터를 만들고, x: count , y: score, 간격: bin size, title입력
*Stem-and-leaf plots
ㄴplot 정렬, 공통점 S 에 추출 L에 순차적 정렬
*Understanding & Comparing Boxplots (Box and Whisker Plots)
ㄴmin/max: lowest 25% , outlier 상자그림을 통해 유효성 검증
*EDA(Ecploratory Data Analysis)
ㄴ기초공사
ㄴpre-processing
cf) 파이썬에서 데이터셋 불러오기 (분기별 재무제표)
1)Description(행, 열의 수, 헤더(이름)이 있는지?, 결측 데이터(Missing data)가 있는지 확인, 원본 형태 확인(미리 파악)
2)pandas.read_csv() :라이브러리에서 데이터셋 불러오고 원인 확인
3)Colab에서는 데이터 사이즈가 큰 경우에는 창이 길어지므로 권장하지 않음
4)헤더가 제대로 읽혀지지 않을 경우: 컬럼의 names를 이용
*로컬상 파일 코랩에 올리는 방법
1)구글 코랩 파일 업로드 패키지(업로드)
2)문장이 아닌 키워드로 구글링
*좋은 데이터셋 요건, 나중에 kaggle을 하겠구나!
*EDA(Ecploratory Data Analysis)
raw data를 바로 분석에 사용하기 어려우므로 '사각형'의 형태를 탐색하는 노력이 필요함
전체적으로 견적을 내는 것으로 초기 분석의 단계를 의미함, 가설을 검정하는 과정을 포함
ㄴ그래픽, 통계(Summary Statistics)
ㄴ타겟: Univariate, Multi-variate(변수들의 관계)
ㄴUni- Non Graphic: Sample data의 Distribution 확인 ec) Numeric(summary statistics): Center, Spread, Modality, Shape, Outliers
ㄴCategorical data: Occurence, frequency, tabulation확인
ㄴUni ex) QQplot .
ㄴMulti-Non Graphic(Relationship을 보는 것이 주 목표, Closs-Tabulation
<과제 문제 보완점>
1) Sheet 각각을 지정해줘야함 : sheet1, sheet2를 각각 read excel, 시트네임에 각 시트 번호 기입해 출력
ㄴ(excel_url, sheet_name='')
2) 데이터 dimension확인 : 방법 여러가지(추가: len(df.Index), len(df2.colums))
3) 결측치 존재 확인: df.isnull()
4) 결측치 0으로 대체: df.fillna('0')
4-1) 결측치 제거: df.dropna()
5) 1열 index사용: df.set_index('1열 이름')
ㄴfor
6) 그래프 그릴 때 matplotlib.pyplot as plt %matplotlib inline , seaborn as sns
7) export csv: DataFrame.to_csv('path\\file_name.csv', sep=',', na_rep='NaN'
ㄴcf) 2차 : df1.to_csv("df1.csv") , print(pd.read.csv('df1.csv')) &df2도 동일하게 수행
8) int화 시키기 a+b=print(int(a)+int(b))
9) max,min추출: df.loc[df.groupby(['target'])['sepal length(cm)'].idxmax()]
ㄴdf.sort_values(by=['target',sepal length(cm)'],ascending=False).drop_duplicates(subset=['target'],keep='first')
10) 그룹화 특정정보 조회: groupby(["",""]).std()
11) 최소, 최대값 구하기
df.groupby('species')[['','']].agg(['최소,최대'])
<과제 최종제출-3차>
1)시트 2개 각각 name설정해줘야함
#데이터셋 url 불러와 변수 이름(df1,df2) 저장
df1=pd.read_excel(excel_url,sheet_name=0)
df2=pd.read_excel(excel_url,sheet_name=1)
2)
#데이터 첫번째 행 확인
df2_columns=df2.iloc[0] #매출액
#index col 삭제
df=pd.read_csv(" ", index_col=0)]
#column 지정
df2.columns=df2_columns
#row 윗단(0~) 제외
df2=df2[1:]
데이터 dimension 확인
print(len(df1.index))
print(len(df1.columns))
ㄴdf1.shape : shape함수로 확인 가능
결측치 존재
df1.isnull()
ㄴ#갯수 확인 df1.isnull().sum(), columns=["결측치 개수"])
#결측치 0으로 대체
df1.fillna('0',inplace=True)
#matplot
#각 데이터 별로 FCF의 값을 barplot으로 시각화
import matplotlib as plt
from matplotlib import pyplot as pllt
##df1=df1.astype(float) #no numeric data to plot 해결
##
#0<큰값, >작은값 수 총합 num1,num2저장
num1=df1.FCF[df1['FCF']>0].value_counts().sum()+df2.FCF[df2['FCF']>0].value_counts().sum()
num2=df1.FCF[df1['FCF']<0].value_counts().sum()+df2.FCF[df2['FCF']<0].value_counts().sum()
##csv로 출력
df1.to_csv("df1.csv")
print(pd.read_csv('df1.csv')) #확인
#Int로 변환
a = '1234'
b = 5678
print(int(a)+int(b))
#species와 sex변수 cross-tabulation을 시행
pp_crosstabulation=pd.crosstab(index=pp["species"],columns=pp["sex"])
# 6개의 값들 중 가장 큰 값을 num3에, 가장 작은 값을 num4
num3=pp_crosstabulation.max()[0]
num4=pp_crosstabulation.min()[0]
>>간과했던 개념
join_d1_d2_d3.groupby('geo')[["PPP"]].agg(['mean'])
'AI(artificial Intelligence)' 카테고리의 다른 글
AI- High dimensional data (0) | 2021.05.25 |
---|---|
AI-Section 1 : Introduction to Data Science-Hypothesis Test (0) | 2021.05.14 |
AI-미분, 경사하강법 (0) | 2021.05.12 |
AI-Data Manipulation (0) | 2021.05.10 |
AI-Feature Engineering (0) | 2021.05.10 |
댓글