조회 수 4847 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print


import 구문


import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from sklearn.linear_model import LinearRegression, LogisticRegression
from sklearn.model_selection import cross_val_score, train_test_split


jupyter notebook에서 파일에 바로 내용을 써 넣어서 채우고 싶을 때


#test2 파일에 쓰기

%%writefile test2
1,2,3,4,5
2,3,4,5,6
7,8,9,0,1



그래프 한글폰트 설정


# 운영 체제마다 한글이 보이게 하는 설정
# 윈도우
import matplotlib.font_manager

if platform.system() == 'Windows':
    path = "c:\Windows\Fonts\malgun.ttf"
    font_name = matplotlib.font_manager.FontProperties(fname=path).get_name()
    plt.rc('font', family=font_name)
# 맥
elif platform.system() == 'Darwin':
    rc('font', family='AppleGothic')
# 리눅스
elif platform.system() == 'Linux':
    rc('font', family='NanumBarunGothic')



datetime 데이터 분해하는 코드


train["d-year"] = train["datetime"].dt.year
train["d-month"] = train["datetime"].dt.month
train["d-day"] = train["datetime"].dt.day
train["d-hour"] = train["datetime"].dt.hour
train["d-minute"] = train["datetime"].dt.minute
train["d-second"] = train["datetime"].dt.second

train[["datetime", "d-year", "d-month", "d-day", "d-hour", "d-minute", "d-second"]].head()


zip파일 압축풀기


local_zip = './data/cats_and_dogs_filtered.zip'
zip_ref = zipfile.ZipFile(local_zip, 'r')
zip_ref.extractall('./data')
zip_ref.close()


폴더 없으면 폴더 만들기. 그리고 wget


if not os.path.exists("./data"):
    os.makedirs("./data")
if not os.path.exists("./data/cats_and_dogs_filtered.zip"):
  !wget --no-check-certificate \
    https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip \
    -O ./data/cats_and_dogs_filtered.zip


csv 파일 읽기


import pandas as pd

df_train = pd.read_csv('data/ratings_train.txt', delimiter='\t', keep_default_na=False)
df_test = pd.read_csv('data/ratings_test.txt', delimiter='\t', keep_default_na=False)

df_train.head()


학습 데이터, 테스트 데이터로 분리하기


import numpy as np
from sklearn.model_selection import train_test_split

X = [[0,1],[2,3],[4,5],[6,7],[8,9]]
Y = [0,1,2,3,4]

# 데이터(X)만 넣었을 경우
X_train, X_test = train_test_split(X, test_size=0.2, random_state=123)
# X_train : [[0,1],[6,7],[8,9],[2,3]]
# X_test : [[4,5]]

# 데이터(X)와 레이블(Y)을 넣었을 경우
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.33, random_state=321)
# X_train : [[4,5],[0,1],[6,7]]
# Y_train : [2,0,3]
# X_test : [[2,3],[8,9]]
# Y_test : [1,4]




Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
35 Python Image 기반 Steganography 예제 1 2019.07.17 25137 0
34 Python 디렉토리 없으면 만들기 2019.03.30 5648 0
33 Python 줄 바꿈 없이 출력하는 방법 2019.03.30 6728 0
32 Python Google Colab에서 파일 업로드/다운로드 팁 2019.03.06 36363 0
» Python pandas, matplot 자주사용하는 코드 2019.03.06 4847 0
30 Python matplot에서 한글이 보이도록 하는 코드 2019.03.06 5973 0
29 Python [tensorflow] 텐서플로우 문서 한글번역본 2018.03.22 5097 0
28 Python [tensorflow] 선형회귀 예제 2018.02.05 5334 0
27 Python json 데이터 핸들링 2017.03.09 8581 0
26 Python pygoogle 파이썬으로 구글 검색결과 가져오기 library 2016.01.20 9826 0
25 Python pyBest 소스 secret 2016.01.20 0 0
24 Python 커맨드 라인에서 컬러로 출력하기 termcolor 2014.06.27 10577 0
23 Python [Sconscript] Install method 2014.05.29 8489 0
22 Python C, Python and swig on Windows with Visual Studio 2014.05.29 11502 0
21 Python Python 유용한 코드 모음 2014.05.20 15102 0
목록
Board Pagination ‹ Prev 1 2 3 Next ›
/ 3

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5