from sklearn import ensemble
model = ensemble.RandomForestClassifier(n_estimators=10)
model.fit(x,y)
predictions = model.predict(new)
나는 숲에있는 나무의 예측 된 클래스 확률의 평균을 계산하여 예측을 얻는 predict()
데 사용 predict_proba()
하는 것을 알고 있습니다.
메서드에서 predict_proba()
예측 한 클래스 의 결과를 얻고 싶습니다 predict()
.
내가하는 일은 predict()
위의 코드에서와 같이 먼저 호출 하고 확률에 대해 다음과 같이 트리에서 최대 확률을 추출하는 것입니다.
all_probabilities = model.predict_proba()
class_probabilities = np.array([])
for tree in all_probabilities:
class_probabilites = np.append(class_probabilities, tree.max())
이 올바른지? 그렇지 않은 경우 예측 클래스의 확률을 어떻게 추출 할 수 있습니까?
이 predict_proba()
메서드는 각 인스턴스와 각 클래스에 대한 예상 확률을 포함하는 2 차원 배열을 반환합니다.
import numpy as np
from sklearn.ensemble import RandomForestClassifier
X = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]])
y = np.array([0, 0, 1, 1])
model = RandomForestClassifier()
model.fit(X, y)
model.predict_proba(X)
array([[0.91, 0.09],
[0.91, 0.09],
[0.25, 0.75],
[0.05, 0.95]])
아시다시피 각 인스턴스에 대해 예측 된 클래스는 최대 확률을 가진 클래스입니다. 따라서 예측 된 클래스에 대한 예상 확률을 얻는 간단한 방법은 다음을 사용하는 것입니다 np.max()
.
np.max(model.predict_proba(X), axis=1)
array([0.91, 0.91, 0.75, 0.95])
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다