E:\python\anaconda\python.exe E:\python\python_workdata\rand_forest.py Traceback (most recent call last): File "E:\python\python_workdata\rand_forest.py", line 12, in <module> X = data.drop(['索引'], axis=1, header=0) File "E:\python\anaconda\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper return func(*args, **kwargs) TypeError: DataFrame.drop() got an unexpected keyword argument 'header'
时间: 2023-06-19 20:05:03 浏览: 121
这个错误提示是因为 `DataFrame.drop()` 函数中没有 `header` 这个参数,你需要将 `header` 改为 `columns`,即将代码中的 `header=0` 改为 `columns=['索引']`,修改后的代码如下:
```python
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
data = pd.read_excel('data.xlsx')
X = data.drop(columns=['索引'])
y = data['索引']
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X, y)
print(model.score(X, y))
```
这样就可以正常运行了。
阅读全文