728x90
반응형
이 예에서는 scikit-learn의 load_iris 함수를 사용하여 iris 데이터셋을 로드합니다.
그런 다음 데이터는 train_test_split 함수를 사용하여 교육 및 테스트 세트로 분할됩니다.
RandomForestClassifier 클래스는 학습 데이터에서 임의 포레스트 분류기를 학습하는 데 사용됩니다.
fit 함수는 훈련 데이터에 분류기를 맞추는 데 사용되고 점수 방법은 테스트 데이터에서 분류기를 평가하는 데 사용됩니다.
마지막으로 분류기의 정확도가 출력되어 테스트 데이터에서 얼마나 잘 수행되었는지 보여줍니다.
저는 정확도가 100%가 나왔네요.
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
# Load the iris dataset
iris = load_iris()
X = iris.data
y = iris.target
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Train the Random Forest classifier
clf = RandomForestClassifier(n_estimators=100, random_state=0)
clf.fit(X_train, y_train)
# Evaluate the classifier on the test data
accuracy = clf.score(X_test, y_test)
print("Accuracy: {:.2f}%".format(accuracy * 100))
728x90
반응형
'코딩' 카테고리의 다른 글
pyautogui를 활용하여 hello world 자동화를 해보자. (0) | 2023.02.08 |
---|---|
pyqt로 가위바위보 게임을 만들어보자. (0) | 2023.02.07 |
가짜 이름, 주소 데이터를 생성하는 파이썬 코드를 만들어보자.(Faker 라이브러리) (0) | 2023.02.05 |
파이썬 덧셈 함수로 리팩토링 예시 (0) | 2023.02.04 |
파이썬으로 http에 요청을 보내서, 응답을 받아보자. (0) | 2023.02.04 |
댓글