본문 바로가기

카테고리 없음

ML library

pytorch

 

 

 

tensorflow

File I/O

data_path = 'gs://flowers-public/*/*.jpg'
labels = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
n_imgs = len(tf.io.gfile.glob(data_path))

# 경로 뽑기
filenames = tf.data.Dataset.list_files(data_path)

#### question 1, 2 ####
for filename in fileset.take(10):
  print(filename.numpy().decode('utf-8'))


#### question 3 ####
# img 값 뽑기
def decode_jpg(filename): # 딱 하나만 할 수 있음
  bits = tf.io.read_file(filename)
  image = tf.image.decode_jpeg(bits)
  return image

images = filenames.map(decode_jpg) # 파이썬 효과 : list를 전부 함수에 돌릴 수 있음

for image in images.take(10):
  print(image.numpy().shape)


# #### question 4 ####
# img + label 뽑기
def decode_jpg_label(filename):
  bits = tf.io.read_file(filename)
  image = tf.image.decode_jpeg(bits)
  label = tf.strings.split(tf.expand_dims(filename, axis=-1), sep='/')
  label = label.values[-2]
  return image, label

dataset = filenames.map(decode_jpg_label)
for image, label in dataset.take(10):
  print(image.numpy().shape, label.numpy().decode('utf-8'))

 

keras

convolution
weight initializer, weight regularizer : layer에서 설정할 수 있음.
tensorflow.keras 쓰기!!!
model fit 후 history: metrics값 저장되있음
y label을 one hot encoding 해줌
transfer learning : 컴파일 전에 해야함.

 

sparse: one_hot output을 y값에 맞게 변경시켜줌 (SparseCategoricalAccuracy, SparseCategoricalAccuracy)

 

 

data 불러오기 : ram차서 병목생김 - 안 좋음, 왠만하면 쓰지마셈

 

 

modeling
img augmentation
callback : early stopping

sklearn

LinearRegression : continuous
RogisticRegression : discrete
shufflesplit : 그냥 index만 생성

pass

gridSearchCV : pass
train_test_split

 

LabelEncoder : 범주형을 숫자로   inverse_transform    fit_transform

 

 

seaborn

factorplot + col : 개이득
countplot hue
kde 분포확인 legend
여러개 한번에 f, ax=plt.subplots
joint, dist, kde
lineplot : 분산 표시

 

box, swarm, count

 

heatmap

pandas

factorize : 가장간단한 encoding

 

 

 

eda 편하게, 아래도 써먹으셈

print 'Train min/max date: %s / %s' % (train.Date.min().date(), train.Date.max().date())
print 'Test  min/max date: %s / %s' % ( test.Date.min().date(),  test.Date.max().date())
print ''
print 'Number of days in train: %d' % ((train.Date.max() - train.Date.min()).days + 1)
print 'Number of days in test:  %d' % (( test.Date.max() -  test.Date.min()).days + 1)
print ''
print 'Train shape: %d rows' % train.shape[0]
print 'Test shape: %d rows'  % test.shape[0]

 

itterows() ~= enumerate
: or은 못 씀
곱하기(*)를 해도 shape만 유지되면 groupby를 쓸 수 있음. (groupby는 shape만 신경 씀)
string 처리하기 (broadcasting)
nunique : number of unique (broadcasting)

 

time series 그래프로 (x: index, y: values) + to_datatime

 

y 값 확인
없애기 : drop
pd.cut
.apply lambda
.loc : 문자열 index
astype
fillna : nan값 처리
value_counts() : y값 세기
groupby()
정렬, sort_values, 특성 꼭 집기
pd.DataFrame(data, columns = )

 

read_csv
sum, mean, discribe
isnull() : nan, null값 확인
drop: 삭제, 제외, nan처리 axis =1 : column을 삭제 (axis=0 보다 복잡하다.)

그 외

msno

mso.matrix

warning

 

 

cv2 (opencv)

 

glob

파일이름 얻기, 파일 입출력

glob() : 이미지 이름