Daily plan
๐์ค์
- SQL ์ฝ๋์นดํ 98, 99 ,100๋ฒ
- 11์ ์คํ ๋ค๋ ๊ฐ์
๐ฅ ์คํ
- 14์ QCC
- 15์ 30๋ถ QCC ํด์ค
๐ ์ ๋
- TIL ์ ์ถํด !!!!
To Do
์ด๋ฒ์ฃผ ๋ชฉํ
select *, min(event_date)
from activity
group by player_id
select activity_date as day,
count(distinct user_id) active_users
from activity
where activity_date between '2019-06-27' and '2019-07-27'
group by activity_date
select teacher_id,
count(distinct subject_id) cnt
from teacher
group by teacher_id
์์ธก ์ ํ๋๊ฐ ๋์์๋ก ์ข์ง๋ง, ์ ํ๋๊ฐ ๋์์ง์๋ก ๊ณผ์ ํฉ ์ฐ๋ ค๋ ์ปค์ง๋ฏ๋ก ์ ์ ํ ๊ท ํ์ ๋ง์ถ์ด์ผ ํจ
from xgboost import XGBClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# ๋ฐ์ดํฐ ๋ก๋ฉ
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, random_state=42)
# ๋ชจ๋ธ ํ์ต
xgb = XGBClassifier(use_label_encoder=False, eval_metric='logloss')
xgb.fit(X_train, y_train)
# ์์ธก ๋ฐ ํ๊ฐ
y_pred = xgb.predict(X_test)
accuracy_score(y_test, y_pred)
from catboost import CatBoostClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# ๋ฐ์ดํฐ ๋ก๋ฉ
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, random_state=42)
# ๋ชจ๋ธ ํ์ต
cat = CatBoostClassifier(verbose=0)
cat.fit(X_train, y_train)
# ์์ธก ๋ฐ ํ๊ฐ
y_pred = cat.predict(X_test)
accuracy_score(y_test, y_pred)
| ํญ๋ชฉ | XGBoost | CatBoost |
|---|---|---|
| ์นดํ ๊ณ ๋ฆฌ ์ฒ๋ฆฌ | ์๋ ์ธ์ฝ๋ฉ ํ์ | ์๋ ์ฒ๋ฆฌ |
| ๊ฒฐ์ธก์น ์ฒ๋ฆฌ | ์๋ ์ฒ๋ฆฌ | ์๋ ์ฒ๋ฆฌ |
| ํ์ต ์๋ | ๋น ๋ฆ | ๋ค์ ๋๋ฆด ์ ์์ |
| ์ด๋ณด์ ์นํ์ฑ | ์ค๊ฐ | ๋์(ํ๋ ์ํฅ์ด ์ ์) |
| ๋ชจ๋ธ ํด์๋ ฅ | ์ค๊ฐ | ์ค๊ฐ |
from sklearn.model_selection import GridSearchCV
from xgboost import XGBClassifier
param_grid = {
'n_estimators': [100,300],
'learning_rate': [0.05, 0.1],
'max_depth': [3, 5],
'subsample':[0.8, 1.0]
}
xgb = XGBClassifier(use_label_encoder=Flase, eval_metric='logloss')
grid_xgb = GridSearchCV(estimator=xgb,
param_grid=param_grid,
cv=3,
scoring='accuracy,
n_jobs=-1)
grid_xgb.fit(X_train, y_train)
grid_xgb.best_params_ # ์ต์ ํ๋ผ๋ฏธํฐ
grid_xgb.best_score_ # ์ต๊ณ ์ ํ๋
use_label_encoder
CatBoost Grid Search ์์
from catboost import CatBoostClassifier
from sklearn.model_selection import GridSearchCV
cat = CatBoostClassifier(verbose=0)
param_grid = {
'iterations':[100,300],
'learning_rate':[0.05,0.1],
'depth':[4,6],
'l2_leaf_reg':[1,3]
}
grid_cat = GridSearchCV(estimator=cat,
param_grid=param_grid,
cv=3,
scoring='accuracy',
n_jobs=-1)
grid_cat.fit(X_train,y_train)
grid_cat.best_params_ #์ต์ ํ๋ผ๋ฏธํฐ
grid_cat.best_score_ #์ต๊ณ ์ ํ๋
### ์ฃผ์!!!
# CatBoost๋ fit() ํธ์ถ ์ cat_features๋ฅผ ์ง์ ํด์ผ ํ ์ ์์ (๋ฒ์ฃผํ์ด ์์ ๋๋ง)
from catboost import CatBoostClassifier
model = CatBoostClassifier(task_type="GPU", devices="0", verbose=0)
select region_name, max(sales) highest_sales
from stores
group by region_name
having count(store_id)>1
order by region_name
select a.name as name_x, b.name as name_y, count(distinct a.cart_id) orders
from cart_products a
cross join cart_products b
on a.cart_id = b.cart_id
and a.name!=b.name
group by 1,2
order by 1,2
cross join๊น์ง๋ ์๊ฐํ๋๋ฐ ๊ทธ ์ดํ์ ์ด๋ป๊ฒ ํด์ผํ ์ง ๋๋ฌด ๋ง๋งํด์ ํ์ฐธ์ ํค๋งธ๋คใ
ใ
join์์ a.name!=b.name ์ด ์กฐ๊ฑด ํ๋ ๋ ๊ฑธ์ด์ฃผ๋ ๊ฑธ ์ ์๊ฐ ๋ชปํ์๊น... ๋ฐ๋ณด๋ค ๋ฐ๋ณด..
select count(distinct o.user_id)
from orders o
left join payments p
on p.user_id = o.user_id
where p.user_id is null
or pay_date>order_date
์๋ ๋ฌธ์ ์ ๋๋ก ์ ์ฝ๋????
'์ฒซ๋ฒ์งธ' ๊ฒฐ์ ์ผ๋ณด๋ค ์ด์ ์ ์ํ์ ์ฃผ๋ฌธํ ์ฌ์ฉ์ ์ถ๋ ฅํ๋ผ๊ณ .....'์ฒซ๋ฒ์งธ'!!!!
with first_payment as(
select user_id, min(pay_date) first_payment_date
from payments
group by 1
)
select count(distinct o.user_id)
from orders o
left join first_payments fp
on fp.user_id = o.user_id
where fp.user_id is null
or first_payment_date>order_date
์ ์ฐ๋ฆฌ ์๊น ์ง๊ฟ๋์ด ํ ๊ฑฐ ์ฌ์ง ๋ค๋ ๋ผ๊ฐ....;;;
velog ์๋์ ์ฅ ํด์ฃผ๋ ์ค ์์๋๋ฐ ์ด๋ ๊ฒ ๋ ๋ฐฐ์ ํ๋ค...
์ฝ๋์นดํ ํ ๊ฒ๋ ๋ ๋ผ๊ฐ๊ณ ์คํ ๋ค๋ ๊ฐ์ ์ ๋ฆฌํ ๊ฒ๋ ๋ค ๋ ๋ผ๊ฐ;;;;;

์ฌ์ง ์ป์ด์๋ค ใ
.ใ
์ฐ๋ฆฌ์กฐ ์ค๋์ ์ด์ ๋ธ๋ฆฌํ
ํด,, ์ค๋์ ๊ณต๋ถ๋ ์์ ์์กํ๊ณ ์ด ๋ง์ด ๋ฐ๋ ํ๋ฃจ์๋ค^^
์ฃผ๋ง ๋์ ๊ผญ ๋จธ์ ๋ฌ๋ ๊ฐ์ ๋ค ๋ค์ด์ผ์ง!!