본문 바로가기

ML DL

9.2 Tensorflow

# 데이터 타입 조정

- 변수(칼럼) 타입 확인: 데이터.dtypes
- 변수를 범주형으로 변경:
  - 데이터['칼럼명'].astype('category')
- 변수를 수치형으로 변경:
  - 데이터['칼럼명'].astype('int')
  - 데이터['칼럼명'].astype('float')
- NA 값의 처리
  - NA 갯수 체크: 데이터.isna().sum()
  - NA 값 채우기: 데이터['칼럼명'].fillna(특정숫자)

 

# 라이브러리 사용

import pandas as pd

 

#파일 읽어오기

아이리스 = pd.read_csv(파일경로)
아이리스.head()

 

 

# 원핫인 코딩 되지 않는 현상 확인

인코딩 = pd.get_dummies(아이리스)
인코딩.head()

 

 

# 칼럼의 데이터 타입 체크

print(아이리스.dtypes)

 

# 품종 타입을 범주형으로 바꾸어 준다

아이리스['품종'] = 아이리스['품종'].astype('category')
아이리스.head()

 

print(아이리스.dtypes)

 

# 카테고리 타입의 변수만 원핫인 코딩

인코딩 = pd.get_dummies(아이리스)
인코딩.head()

 

 

# NA 값 체크

아이리스.isna().sum()

 

 

아이리스.tail()

 

 

# NA 값에 꽃잎폭, 평균값을 넣어주는 방법

 

mean = 아이리스['꽃잎폭'].mean()
print(mean)
아이리스['꽃잎폭'] = 아이리스['꽃잎폭'].fillna(mean)
아이리스.tail()

 

import numpy as np

 

x1 = np.array([5.1, 3.5, 1.4, 0.2])
print(x1.ndim, x1.shape)

 

x2 = np.array([4.9, 3.0, 1.4, 0.2])
x3 = np.array([4.7, 3.2, 1.3, 0.2])

 

iris = np.array([x1, x2, x3])
print(iris.ndim, iris.shape)

img1 = np.array([
                [0, 255],
                [255, 0]
                ])
print(img1.ndim, img1.shape)

img2 = np.array([
                [255, 255],
                [255, 255]
                ])

img3 = np.array([
                [0, 0],
                [0, 0]
                ])

 

imageSet = np.array([img1, img2, img3])
print(imageSet.ndim, imageSet.shape)

3 (3, 2, 2)

3 (3,

2, 2)

 

 

728x90