如何在Python中动态构建模型?
我有一个带有Alogitthm和超级参数的列的数据框,均以字符串格式,
看起来像这样。
id Alg
------------
1 RandomForestClassifier(max_depth=2, random_state=0)
2 LinearRegression(n_jobs=-1)
3 RandomForestClassifier(n_estimators=750)
4 ExtraTreesClassifier(criterion='entropy')
有什么方法可以动态运行该算法?
所以我的代码将是这样的
for strCode in df["Alg"]:
model = SomeFunction(strCode) # <---------------- strCode should run dynamically so model can be generated
model.fit(X_train, y_train)
I have a dataframe that has a column with an alogitthm and hyperparameters all in string format
it looks like this.
id Alg
------------
1 RandomForestClassifier(max_depth=2, random_state=0)
2 LinearRegression(n_jobs=-1)
3 RandomForestClassifier(n_estimators=750)
4 ExtraTreesClassifier(criterion='entropy')
is there a way I can run the algorithm dynamically?
so my code will be something like this
for strCode in df["Alg"]:
model = SomeFunction(strCode) # <---------------- strCode should run dynamically so model can be generated
model.fit(X_train, y_train)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在寻找
evary()
函数将传递的字符串评估为python表达式。You might be looking for the
eval()
function which evaluates the passed string as a python expression.