Daily plan
🌞오전
- SQL 코드카타 101, 102, 103번
- 10시 통계 라이브세션
- 11시 30분 스탠다드 수업
🔥 오후
- 14시 국취제 센터 방문
- 머신러닝 강의 1-6, 1-7, 1-8
- 통계 라이브세션 정리 복습
- 스탠다드 수업 정리 복습
🌝 저녁
- TIL 제출해 !!!!
이번주 목표
select product_id, year as first_year, quantity, price
from (select *,
dense_rank() over(partition by product_id order by year) rn
from Sales)a
where rn=1
group by product_id
having min(year)
이라고 작성했다가 having절에는 조건문을 써야한대서 year=min(year)로 썼다.
근데 그러면 quantity, price와 같은 다른 컬럼에는 조건이 적용이 안돼서 오답이 됨.
서브쿼리를 쓰는 방식으로 바꾸어서
처음에 row_number를 사용하여 product id별로 가장 오래된 연도의 데이터만 가져오려고 했는데, 그럼 또 동일한 연도의 데이터 중 하나만 출력되는 오류가 발생함.
결국 dense_rank를 사용해서 겨우 정답을 얻었다.
select class
from courses
group by class
having count(student)>=5
select user_id,
count(follower_id) as followers_count
from followers
group by user_id
order by user_id
지도 학습
: 정답이 있는 데이터를 활용해 훈련 데이터로부터 결과에 대한 예측을 만들어냄
비지도 학습
: 정답이 없는 데이터를 분석하여 그 안에 숨어있는 패턴을 찾거나 데이터를 그룹화시키는 알고리즘
지도학습은 비지도학습보다 더 정확한 경향이 있지만, 데이터에 적절한 레이블 지정을 위해서 사전에 "데이터분석가의 주관" 개입이 필요함
비지도 학습은 레이블이 지정되지 않은 데이터의 고유한 구조 발견을 위해 자체적으로 작동하지만, 결과의 유효성을 검사하려면 여전히 "데이터분석가의 주관" 개입이 필요함
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
# 예시
y_true = [0,1,1,0,1,0,1]
y_pred = [0,0,1,0,1,1,1]
cm = confusion_matrix(y_true, y_pred)
disp = ConfusionMatrixDisplay(confusion_matrix=cm)
disp.plot()

from sklearn.metrics import roc_curve, roc_auc_score
import matplotlib.pyplot as plt
# 예시
y_prob = [0.1, 0.4, 0.8, 0.35, 0.9, 0.6, 0.75]
fpr, tpr, thresholds = roc_curve(y_true, y_prob)
plt.plot(fpr, tpr, label=f"AUC={roc_auc_score(y_true, y_prob):.2f}")
plt.plot([0,1],[0,1],'k--') # 대각선 기준선
plt.xlabel("False Positive Rate")
plt.ylabel("True Positive Rate")
plt.title("ROC Curve")
plt.legend()
plt.grid(True)
plt.show()

from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# 데이터 준비
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = RandomForestClassifier()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(classification_report(y_test, y_pred)

요약
- 정확도만 보지 말고 정밀도, 재현율, F1도 꼭 함께 봐야 함!
- ROC/AUC, 혼동 행렬을 통해 모델의 전체적인 성능 흐름을 시각화
- 실전에서 항상 불균형 데이터 문제를 주의해야 함
볼 일이 있어서 외출할 겸 머리도 자르고 왔다 ㅎㅎㅎ
근데 외출을 해서 그런지 공부가 하나도 손에 안잡힘...
머신러닝 강의 빨리 다 들어야 하는데...!!!ㅜㅜㅜ

누가 제일 금쪽이인지 말 안해도 다들 알겠죠..?ㅜㅜ
금쪽이 팀장곤듀 감시하느라 팀원들 등골빠짐ㅜ
헐 머리자른거 봐야돼