본문 바로가기

소소한/#Python

(6)
Optuna를 활용 xgboost hyperparameter 튜닝 https://www.kaggle.com/code/hamzaghanmi/xgboost-catboost-using-optuna#Optuna:-A-hyperparameter-optimization-framework XGBoost & Catboost Using Optuna 🏄🏻‍♂️ Explore and run machine learning code with Kaggle Notebooks | Using data from Tabular Playground Series - Jan 2021 www.kaggle.com 참고하였음
StratifiedKfold로 성능 검증하기 KFold의 경우 순차적으로 샘플을 추출 하기때문에 오류가 발생할 수 있다. 이에 StratifiedKFold를 활용하여 그 오류를 줄일 수 있다. 모델은 xgboost를 활용하고 검증은 MAE(Mean Absolute Error) 방식이다 from sklearn.model_selection import StratifiedKFold from xgboost import XGBRegressor from sklearn.metrics import mean_absolute_error skf= StratifiedKFold(n_splits=5, shuffle=True, random_state=50) print(skf) n_itr = 0 #model 선언 xgb = XGBRegressor(learning_rate =0..
모델검증 train_test_split from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.2, random_state = 5) print('TrainSet', X_train.shape) print('TrainSet', X_test.shape) print('testSet', y_train.shape) print('testSet', y_test.shape) plt.figure(figsize = (12,4)) plt.subplot(121) plt.scatter(X_train.iloc[:,0], X_train.iloc[:,3], alpha = 0.8) plt.title('Trai..
[ML-Python] 회귀 분류 학습 일반적인 데이터셋을 활용한 모델 학습 - 검증 과정에 대한 대략적인 내용을 정리해 보았다. 1) 불러오기 import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import warnings; warnings.filterwarnings(action='ignore') #경고 메세지 무시 from sklearn.model_selection import train_test_split #훈련 데이터, 테스트 데이터 분리 #from sklearn.ensemble import RandomForestClassifier as RFC #랜덤 포레스트 분류 알고리즘 from sklearn.preprocessing ..
[Python] Pip install 안될 때 파이썬을 별도로 설치 하였을때 'cmd'에서 pip install 이 먹지 않을때는 보통 아래와 같이 해결하면 된다. '시스템 환경 변수 편집' '파이썬 경로 설정' 새로 만들기 C:\Users\Administrator\AppData\Local\Programs\Python\Python38 C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Scripts 위 두개 추가
#01.python : List 만들기 및 출력 프로그래밍을 배우고자 시작했다.간단한 것 부터 차근차근히 해나가자. 모든 자료는 "Head first python - 한빛미디어"를 기반으로 쓰여진다. #01 파이썬을 시작하기 앞서 몇가지 주의사항 1) " " 인용부호를 사용하여 문자열로 변환 2) 각 리스트의 항목은 콤마로 분리 3) 전체 리스트 항목은 대괄호 [ ] 4) 대입연산자(=)를 사용하기 위해 식별자에 리스트를 대입 간단한 예제 코드를 보면 star = [ "albireo", "Alcor", "Mizar"] 리스트는 배열과 같으므로 먼저 작성된 것이 항목#0 이다. print 내장함수를 사용해 리스트 데이터에 접근할 수 있다. print(star[1])