본문 바로가기
Study/Kaggle

[Kaggle] 주택 가격 예측 EDA #1(Kaggle 데이터 불러오기, EDA)

by jijizy 2023. 12. 27.
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