내가 까먹을까봐 만든 블로그

전체 글

Data Science/ML & DL

Cross Entropy에 대한 고찰(with Softmax)

Cross EntropyCross Entropy는 확률 분포 간의 차이를 측정하는 지표로, 분류 문제에서 모델의 예측 성능을 평가하는 데 자주 사용된다. 이는 손실 함수의 한 종류이며, 손실 함수의 목표는 모델이 예측한 분포와 실제 분포 사이의 차이를 최소화하는 것이다. Cross Entropy를 이해하기 전 먼저 짚고 넘어가야 하는 개념이 있는데 바로 놀람도, 기대값, 엔트로피 이 세 가지이다. 먼저 놀람도에 대한 예를 들어보자.검은색 종이 999개와 흰색 종이가 1개 들어있는 상자가 있다고 가정하자. 이 상자에서 우리가 검은색 종이를 뽑았다면 우리는 당연하다고 생각할 것이다. 확률(\( p(x) \))이 훨씬 높기 때문이다. 하지만 흰색 종이가 나온다면 우리는 놀라게 될 것이다. 다시 말하면 이 놀람..

Coding Test

[Python] 백준 2161 - 카드1

문제https://www.acmicpc.net/problem/2161 해설큐의 구조를 활용하면 된다. def solution(cards): answer = [] while len(cards)-1: answer.append(cards.pop(0)) cards.insert(len(cards)-1, cards.pop(0)) answer.append(cards.pop(0)) return " ".join(answer)num = int(input())print(solution([str(i+1) for i in range(num)]))

Coding Test

[Python] 프로그래머스 - 같은 숫자는 싫어

문제https://school.programmers.co.kr/learn/courses/30/lessons/12906 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 해설중복 제거 후 원본 순서대로 반환하는 로직이다. 자연어 처리에서 단어 Encoding 방식인 바이트 페어 인코딩(Byte Pair Encoding, BPE)과 유사하다.def solution(arr): answer = [] for v in arr: if not arr or answer[-1] != v: answer.append(v) return answer

Coding Test

[Python] 백준 10845 - 큐

문제https://www.acmicpc.net/problem/10845 해설큐의 동작을 구현하는 문제이다. def solution(command): queue = [] for c in command: if c[0] == "push": queue.append(c[1]) elif c[0] == "pop": print("-1" if len(queue) == 0 else queue.pop(0)) elif c[0] == "size": print(len(queue)) elif c[0] == "empty": print("1" if len(queue) == 0 else "0") ..

Coding Test

[Python] 백준 12605 - 단어순서 뒤집기

문제https://www.acmicpc.net/problem/12605 해설간단한 문자열 뒤집기였다. 여러 가지 방식으로 접근하여 문제를 해결해 보았다. Solution 1.스택을 사용하여 하나씩 pop 하는 걸 의도했을지도 모르겠지만 제목 그대로 나는 단어순서만 역정렬하여 해결하였다.  def solution(lst): for i, s in enumerate(lst): sentence = " ".join(s) print(f"Case #{i+1}: {sentence}")cnt = int(input())sentences = [input().split(" ")[::-1] for _ in range(cnt)]solution(sentences) Solution 2.아무 쓸모도 없고..

Coding Test

[Python] 백준 10828 - 스택

문제https://www.acmicpc.net/problem/10828 해설스택을 구현하는 문제였다. def solution(command): stack = [] for c in command: if c[0] == "push": stack.append(c[1]) elif c[0] == "pop": print("-1" if len(stack) == 0 else stack.pop()) elif c[0] == "size": print(len(stack)) elif c[0] == "empty": print("1" if len(stack) == 0 else "0") ..

AlienCoder
외부 저장소
loading