首页 > 解决方案 > 使用不同笔记本的功能时出现键错误 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

我究竟做错了什么?

标签: pythonjupyter-notebook

解决方案


我查了签名:RandomForestClassifier(n_estimators=’warn’, criterion=’gini’, max_depth=None, ...)

你的代码RandomForestClassifier(n_estimators, max_depth)应该是RandomForestClassifier(n_estimators, max_depth=max_depth)


推荐阅读