I am using a random forest in a jupiter notebook to predict something. I have a separate notebook in the same working directory, in which I have specified the functions. I am able to use all functions from the functions notebook (for example data transformation functions), however I cannot use the specific function containing the RandomForestClassifier from sklearn. (Gives Key Error: 40)
I use:
import import_ipynb
import functions
at the beginning of the notebook to import the functions notebook, and then use functions.function_name to call the functions.
I have already tried restarting the kernels and reloading the functions.
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
what am I doing wrong?
I Looked up the signature: RandomForestClassifier(n_estimators='warn', criterion='gini', max_depth=None, ...)
Your code RandomForestClassifier(n_estimators, max_depth)
should be RandomForestClassifier(n_estimators, max_depth=max_depth)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.