목표
유방암 데이터셋으로 데이터 분석. 머신러닝 모델 학습(F1 Score 80 넘기기)
결과
https://www.kaggle.com/datasets/akshaydattatraykhare/diabetes-dataset
Diabetes Dataset
Diabetes Patients Data
www.kaggle.com
위 사이트의 데이터 사용
In [ ]:
from google.colab import drive
drive.mount('/content/drive')
Mounted at /content/drive
In [ ]:
import numpy as np # 배열들의 연산을 해주는 라이브러리
import pandas as pd # 주로 DataFrame이라고 불리는 이차원 배열을 처리하는 라이브러리
In [ ]:
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import f1_score
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
In [ ]:
path = '/content/drive/MyDrive/Colab Notebooks/data/diabetes/' # 파일 경로
In [ ]:
data = pd.read_csv(path + 'diabetes.csv')
In [ ]:
data.head()
Out[ ]:
Pregnancies | Glucose | BloodPressure | SkinThickness | Insulin | BMI | DiabetesPedigreeFunction | Age | Outcome | |
---|---|---|---|---|---|---|---|---|---|
0 | 6 | 148 | 72 | 35 | 0 | 33.6 | 0.627 | 50 | 1 |
1 | 1 | 85 | 66 | 29 | 0 | 26.6 | 0.351 | 31 | 0 |
2 | 8 | 183 | 64 | 0 | 0 | 23.3 | 0.672 | 32 | 1 |
3 | 1 | 89 | 66 | 23 | 94 | 28.1 | 0.167 | 21 | 0 |
4 | 0 | 137 | 40 | 35 | 168 | 43.1 | 2.288 | 33 | 1 |
In [ ]:
X_train, X_test, y_train, y_test = train_test_split(data.iloc[:, :-1], data.iloc[:, -1], test_size=0.2, random_state=42) # 학습, 테스트 데이터 분류
In [ ]:
y_train.head()
Out[ ]:
60 0 618 1 346 0 294 0 231 1 Name: Outcome, dtype: int64
In [ ]:
model = RandomForestClassifier(
n_estimators=20, ## 붓스트랩 샘플 개수 또는 base_estimator 개수
criterion='entropy', ## 불순도 측도
max_depth=5, ## 개별 나무의 최대 깊이
oob_score=True, ## Out-of-bag 데이터를 이용한 성능 계산
random_state=42, ## 랜덤 시드
)
model.fit(X_train, y_train) # 모델 학습
predict = model.predict(X_test) # 예측
# 평가
print('Accuracy:', accuracy_score(y_test, predict))
print('Confusion Matrix:\n', confusion_matrix(y_test, predict))
print('F1 Score:', f1_score(y_test, predict))
Accuracy: 0.7727272727272727 Confusion Matrix: [[82 17] [18 37]] F1 Score: 0.6788990825688074
'2024 하계 모각코' 카테고리의 다른 글
모각코 5회차 - 7/29일, 14시~17시 (1) | 2024.07.29 |
---|---|
모각코 4회차 - 7/24일, 14시~17시 (2) | 2024.07.24 |
모각코 2회차 - 7/8일, 14시~17시 (1) | 2024.07.08 |
모각코 1회차 - 7/3일, 14시~17시 (2) | 2024.07.03 |