我有一个愚蠢的问题。
我已经在 scikit learn 中进行了交叉验证,并希望使用我为每个模型获得的值制作更直观的信息。
但是,我不能只访问要插入到数据框中的模板名称。始终与参数一起提供。是否有一些创建对象的方法只访问模型的名称,没有它的参数。还是我必须创建一个带有名称的外部列表?
我使用:
for model in models:
scores = cross_val_score(model, X, y, cv=5)
print(f'Name model: {model} , Mean score: {scores.mean()}')
但是我得到的是带参数的名字:
Name model: LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False), Mean score: 0.8066782865537986
其实我想这样获取信息:
Name Model: LinearRegression, Mean Score: 0.8066782865537986
谢谢!
最佳答案
你可以这样做:
model_name = type(model).__name__
如在
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:11)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.linear_model import LinearRegression
>>> model = LinearRegression()
>>> model_name = type(model).__name__
>>> print(model_name)
LinearRegression
关于python - SciKit Learn 如何只获取模型对象的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52763325/