【发布时间】:2021-04-20 22:46:32
【问题描述】:
我有一些模型,我正在尝试将它们全部拟合。
目前我已经尝试过使用字典并适合它们:
dictionary_of_models = {'catboost':CatBoostClassifier(random_state=0,), 'logistic_regression':LogisticRegression(random_state=0)}
for model in dictionary_of_models.keys():
print(model)
dictionary_of_models[model]=model.fit(X_train, y_train)
但是,即使模型被打印出来,我也会收到这个错误:
model.fit(X_train, y_train)
AttributeError: 'str' object has no attribute 'fit'
代码有什么问题?
我认为字符串将传递给 fit 函数而不是模型对象,但我不知道我可以从字典创建模型,除非我尝试过。
【问题讨论】:
标签: python python-3.x dictionary machine-learning scikit-learn