728x90
1. Colab에서 캐글 데이터 불러오기 - Kaggle
# Kaggle KPI 설치
!pip install kaggle
# Kaggle Token 다운로드
from google.colab import files
uploaded = files.upload()
for fn in uploaded.keys():
print('uploaded file "{name}" with length {length} bytes'.format(
name=fn, length=len(uploaded[fn])))
# kaggle.json을 아래 폴더로 옮긴 뒤, file을 사용할 수 있도록 권한을 부여함
!mkdir -p ~/.kaggle/ && mv kaggle.json ~/.kaggle/ && chmod 600 ~/.kaggle/kaggle.json
# 파일업로드 성공 확인
ls -1ha ~/.kaggle/kaggle.json
# return(파일업로드 성공 시) : /root/.kaggle/kaggle.json
# Kaggle 데이터 불러오기
!kaggle competitions list
# 원하는 대회 데이터셋 불러오기
!kaggle competitions download -c house-prices-advanced-regression-techniques
2. 구글 드라이브와 연동하여 데이터 저장 - Google Drive
# 구글 드라이브 마운트
from google.colab import drive # 패키지 불러오기
ROOT = "/content/drive" # 드라이브 기본 경로
print(ROOT) # print content of ROOT (Optional)
drive.mount(ROOT) # 드라이브 기본 경로 Mount
# 프로젝트 파일 생성 및 다운받을 경로 이동
from os.path import join
MY_GOOGLE_DRIVE_PATH = 'My Drive/Colab Notebooks/inflearn_kaggle/data'
PROJECT_PATH = join(ROOT, MY_GOOGLE_DRIVE_PATH)
print(PROJECT_PATH)
# 구글 드라이브 내 해당 폴더로 이동
%cd "{PROJECT_PATH}"
# 구글 코랩에서 캐글 데이터 불러오기(반복)
3. EDA 기본 개념
- EDA(Exploratory Data Analysis) : 탐색적 데이터 분석
- 샘플에 대한 탐색적 자료 분석을 통해 모수 데이터를 이해하는 것
- Confirmatory Data Analysis(가설검정, 분산분석, T-검정 등)
4. 캐글 대회 및 데이터 확인
# 구글 드라이브 연동(반복)
# EDA 패키지 설치
import pandas as pd
import pandas_profiling # 보고서 기능
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from IPython.core.display import display, HTML
# 데이터 수집
train = pd.read_csv('data/train.csv')
test = pd.read_csv('data/test.csv')
print("data import is done")
# 데이터 확인
train.shape, test.shape
# return : ((1460, 81), (1459, 80))
# 상위 5개 데이터 확인
display(train.head())
# numerical 변수 추출
numeric_features = train.select_dtypes(include=[np.number]) # 수치형 데이터
print(numeric_features.columns)
print("The total number of numeric features are: ", len(numeric_features.columns))
# categorical 변수 추출
categorical_features = train.select_dtypes(exclude=[np.number]) # 수치형 데이터 제외한 나머지
print(categorical_features.columns)
print("The total number of numeric features are: ", len(categorical_features.columns))
728x90
'Study > Kaggle' 카테고리의 다른 글
[Kaggle] 아마존 리뷰 분석 #02(EDA, 감정분석) (1) | 2024.06.23 |
---|---|
[Kaggle] 아마존 리뷰 분석 #01(데이터 불러오기, 전처리) (0) | 2024.06.21 |
[Kaggle] 주택 가격 예측 EDA #3(결측치, 이상치 처리) (0) | 2024.01.02 |
[Kaggle] 주택 가격 예측 EDA #2(시각화) (0) | 2023.12.29 |
[Kaggle] 기초문법 (0) | 2023.11.14 |