반응형

Programing 144

Sklearn - PolynomialFeatures

Feature Engineering은 데이터의 전처리를 통해 머신러닝 모델의 성능을 향상시키는 방법입니다. PolynomialFeatures 는 주어진 입력값을 기반으로, 고차항들을 추가하는 방법입니다. scikit-learn의 패키지에서 이 기능을 제공하며, 단순한 선형모델을 활용한다는 가정 하에 보다 복잡한 다항식 모델로 변환시킬 수 있기 때문에, 입력값이 적고 비선형 데이터에 대한 모델링을 수행할 때 효과적입니다. - 기본 사용 방법 from sklearn.preprocessing import PolynomialFeatures poly = PolynomialFeatures(degree=2, include_bias=False) poly.fit_transform(pd.DataFrame([3, 6, 9]..

tf.keras로 Embedding layer 뜯어보기, 구현해보기

Embedding layer가 어떻게 동작하는지 정확하게 알기 위해서, 가장 쉬운 예제를 통해 이해하려고 노력해봤습니다. import tensorflow as tf from tensorflow.keras.utils import plot_model query_input = tf.keras.Input(shape=(5), dtype='int32') token_embedding = tf.keras.layers.Embedding(input_dim=5, output_dim=10) query_embeddings = token_embedding(query_input) Model = tf.keras.models.Model(inputs = query_input, outputs=query_embeddings) Model: ..

tf.keras에서 Transformer의 self attention 및 중요도

1. Transformer에서 self-attention의 의미 Self-attention은 자연어 텍스트와 같은 Sequential data를 처리하기 위한 Transformer layer에 있는 메커니즘입니다. 이를 통해 모델은 시퀀스의 중요한 부분에 집중하여 시퀀스의 각 요소에 대한 표현을 계산할 수 있습니다. Attention score는 위 그림처럼, 2차원의 word vector에 대해 Matrix multiplication이 수행됩니다. Word embedding이 잘 되어있다면, 비슷한 의미를 가지는 단어는 비슷한 Feature pattern을 보일 것입니다. 따라서, 같은 문장의 MatMul을 통해 만들어진 Attention score (Matrix)는 '유사도' 처럼 작동할 것입니다. ..

01. 윈도우 Flutter 설치 및 세팅, Hello world!

1. Flutter 다운로드 https://docs.flutter.dev/get-started/install Install Install Flutter and get started. Downloads available for Windows, macOS, Linux, and Chrome OS operating systems. docs.flutter.dev c:\\flutter\에 압축풀기 2. 환경변수 설정 Path에 c:\flutter\flutter\bin 등록하기 3. 안드로이드 스튜디오 설치 https://developer.android.com/studio/archive?hl=ko Android 스튜디오 다운로드 자료실 | Android 개발자 | Android Developers 이 페이지에는 An..

Programing/Flutter 2022.10.28

tf.Keras 기본코드로 이해하는 Transformer

뭔가 Transformer는 참 항상 어렵게 느껴졌었다. 왜이렇게 강의들이나 문헌들이 어렵게 적혀있는지, Key, Query, Value는 도대체 어디서 튀어나오는 것인지 명확하게 이해가 안됐다. 내가 이해할 수 있도록 글을 쓰면, 독자분들도 쉽게 이해할 수 있지 않을까? 라는 마음으로 이 글을 한번 써보도록 한다. 코드는 모델링을 기준으로 상세하게 덧붙여 가며 설명한다. 0. Library & 예제 데이터 준비 - Tensorflow Keras, Library Load import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras.models import Sequent..

R - Cross-validation 평균 ROC 그리기

Split validation이나, Leave-One-Out Cross-validation (LOOCV) 를 하게 되면 적절하게 ROC curve를 그릴 수 있다. Split validation은 test set이 명확하게 있으니, 해당 샘플에 대해 ROC curve를 그리면 되고, LOOCV의 경우 데이터 하나당 Prediction 값을 저장해놓고 ROC curve를 그리면 된다. 그러면 Cross-validation은?? AUC 구하는거야, MRMC 기법이든 뭐든, 어쨌건 결과 값이 각 fold 별 AUC의 평균과 동일하기에 계산하면 되는데 ROC가 항상 문제이다. Multiple ROC curve에 대한 평균을 구하는 방식으로, Cross-validation의 mean ROC를 시각화 할 수 있는데..

몬티홀 딜레마, R 프로그래밍 솔루션

Suppose you’re on a game show, and you’re given the choice of three doors. Behind one door is a car, behind the others, goats. You pick a door, say #1, and the host, who knows what’s behind the doors, opens another door, say #3, which has a goat. He says to you, "Do you want to pick door #2?" Is it to your advantage to switch your choice of doors? 당신이 한 게임 쇼에 참여하여 세 문들 중 하나를 고를 기회를 가졌다고 생각해봐라. 한..

반응형