AI (인공지능) 머신러닝을 쉽게 구현할 수 있도록 도와주는 사이킷런(Scikit-Learn) 에 대해 알아보자.
주요 특징
- 다양한 머신러닝 알고리즘 제공: 지도 학습(Supervised Learning)과 비지도 학습(Unsupervised Learning) 모두 지원
- 데이터 전처리 기능: 스케일링, 정규화, 결측값 처리 등 제공
- 모델 평가 및 선택 도구 제공: 교차 검증, 하이퍼파라미터 튜닝(GridSearchCV, RandomizedSearchCV) 등 지원
- 사용이 간편한 API: 일관된 인터페이스로 쉽게 학습 및 예측 가능
설치 방법
pip install scikit-learn
간단한 예제: 로지스틱 회귀(Logistic Regression)
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score
# 데이터 로드
iris = load_iris()
X, y = iris.data, iris.target
# 데이터 분할
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 데이터 정규화
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# 모델 학습
model = LogisticRegression()
model.fit(X_train, y_train)
# 예측 및 평가
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy:.2f}")
자주 사용되는 기능
- 지도 학습 (Supervised Learning)
- 회귀: LinearRegression, Ridge, Lasso
- 분류: LogisticRegression, SVC, RandomForestClassifier
- 비지도 학습 (Unsupervised Learning)
- 클러스터링: KMeans, DBSCAN
- 차원 축소: PCA, t-SNE
- 모델 평가 및 선택
- train_test_split, cross_val_score
- GridSearchCV, RandomizedSearchCV
ChatGPT 맞습니다 ^^
'Python' 카테고리의 다른 글
[Python] 간단한 Tensorflow LSTM 예제 by ChatGPT (0) | 2023.06.01 |
---|---|
[python] schedule 을 이용한 프로그램 시작 종료 (2) | 2023.05.19 |
[Python] time datetime 을 이용한 시간(datetime) 출력 (0) | 2023.04.04 |
[python] Numpy 를 이용한 1~10까지 더하기 : 누적합(Cumulative Sum) (0) | 2021.11.10 |
[Python] 함수 만들기 (0) | 2021.11.03 |