1
A
답변
0
메서드 show_most_informative_features()
은 요청한 기능을 인쇄하고 None
을 반환합니다. 기능 이름의 목록과 "정보 성"를 반환하려면 다음을 사용 :
features = classifier.most_informative_features(10)
당신은 다음과 같이 표시 될 수 쌍의 목록을 얻을 것이다 :
for f, w in features:
print(f, w)
0
솔루션 python3에서 작동을 저장 to output_string 변수에.
from io import StringIO
import contextlib
import sys
@contextlib.contextmanager
def stdout_redirect(where):
sys.stdout = where
try:
yield where
finally:
sys.stdout = sys.__stdout__
with stdout_redirect(StringIO()) as new_stdout:
classifier.show_most_informative_features(15)
new_stdout.seek(0)
# output assigned to variable
output_string = new_stdout.read()
'classifier' 객체는 그 기능을 표시하는 대신 이러한 기능을 반환하는 메소드가 있습니까, 아니면이를 보유하고있는 인스턴스 변수입니까? 그것이 내가 볼 곳입니다. 당신의 질문은 실제로 방법을 표시하는 대신에 그 방법으로 보여지는 내용을 얻는 방법입니다. 변수가'None'을 참조하는 것은 당신에게 도움이되지 않습니다. – timgeb