所以我试图实现额外的树分类器,以便在我的数据库中找到参数的重要性,我写了这个简单的代码,但由于某种原因,我不断得到这个错误。我的代码:import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%matplotlib inlinefrom sklearn.ensemble import ExtraTreesClassifier df = pd.read_csv('C:\\Users\\ali97\\Desktop\\Project\\Database\\5-FINAL2\\Final After Simple Filtering.csv')extra_tree_forest = ExtraTreesClassifier(n_estimators = 5, criterion ='entropy', max_features = 2) extra_tree_forest.fit(df)feature_importance = extra_tree_forest.feature_importances_ feature_importance_normalized = np.std([tree.feature_importances_ for tree in extra_tree_forest.estimators_], axis = 1)plt.bar(X.columns, feature_importance_normalized) plt.xlabel('Lbale') plt.ylabel('Feature Importance') plt.title('Parameters Importance') plt.show() 错误:TypeError Traceback (most recent call last)<ipython-input-7-4aad8882ce6d> in <module> 16 extra_tree_forest = ExtraTreesClassifier(n_estimators = 5, criterion ='entropy', max_features = 2) 17 ---> 18 extra_tree_forest.fit(df) 19 20 feature_importance = extra_tree_forest.feature_importances_TypeError: fit() missing 1 required positional argument: 'y'
1 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
通常,对于拟合函数,我们需要同时具有属性(X)和标签(Y),并且您需要使用它来训练此分类器。我建议您拆分标签和属性,并在导入时将其作为两个单独的列表导入。extra_tree_forest.fit(X, Y)
Final After Simple Filtering.csv
添加回答
举报
0/150
提交
取消