在SkLearn中打印估算器名称

Odi*_*seo 3 python model scikit-learn

在Sklearn中,是否可以打印出估算器的类名?

我尝试使用name属性,但是不起作用。

from sklearn.linear_model import LogisticRegression  

def print_estimator_name(estimator):
    print(estimator.__name__)

#Expected Outcome:
print_estimator_name(LogisticRegression())
Run Code Online (Sandbox Code Playgroud)

我希望这会打印出上面的分类器名称

Wil*_*tam 5

我认为您正在寻找estimator.__class__.__name__即:

from sklearn.linear_model import LogisticRegression

def print_estimator_name(estimator):
    print(estimator.__class__.__name__)

#Expected Outcome:
print_estimator_name(LogisticRegression())
Run Code Online (Sandbox Code Playgroud)