python - 使用不同笔记本的功能时出现键错误 40
问题描述
我在木星笔记本中使用随机森林来预测某些东西。我在同一个工作目录中有一个单独的笔记本,我在其中指定了函数。我可以使用函数笔记本中的所有函数(例如数据转换函数),但是我不能使用包含来自 sklearn 的 RandomForestClassifier 的特定函数。(给出关键错误:40)
我用:
导入 import_ipynb
导入函数
在 notebook 开头导入函数 notebook,然后使用 functions.function_name 调用函数。
我已经尝试重新启动内核并重新加载功能。
在主笔记本中调用函数
clf = functions.random_forest_classifier(X_train, y_train, n_estimators = 30, max_depth = 40)
这是函数笔记本中的函数
def random_forest_classifier(X_train, y_train, n_estimators, max_depth):
clf = RandomForestClassifier(n_estimators, max_depth)
clf.fit(X_train, y_train)
return clf
我究竟做错了什么?
解决方案
我查了签名:RandomForestClassifier(n_estimators=’warn’, criterion=’gini’, max_depth=None, ...)
你的代码RandomForestClassifier(n_estimators, max_depth)
应该是RandomForestClassifier(n_estimators, max_depth=max_depth)
推荐阅读
- python - Django - Export CSV in ManytoMany Field
- python - 如何从网站的所有页面中抓取数据并将其写入文件?
- c++ - C ++:结构中的函数是否与结构一起复制?
- javascript - TensorFlow 语音命令识别分数
- javascript - 由于无法找到那里的路由路径,部署构建失败?
- excel - 我有 55,000 行租赁数据要清理,数据不一致并且包含文本和数字
- c++ - 容器的 C++ 堆栈限制
- python - Python lxml打印每个表格行
- python - 当我在 Flask 中使用 @login_required 时出现问题
- jquery - 动态添加行时检测对表单的更改