gpt4 book ai didi

python - 在拟合随机森林分类器时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-04 05:41:55 24 4
gpt4 key购买 nike

我正在使用 IPython 的 UI 和适当的库(Anaconda、pandas、numpy)

我已经声明了一个 pandas 对象 df,我已经对其进行了更改,以便第一列是我希望预测的所需值,但我的代码仍然继续停在第 10 行。第 11 行没有运行。相反,终端 IPython 窗口退出并显示此错误:

~/anaconda/bin/python.app: line 3: 45581 Killed: 9               ~/anaconda/python.app/Contents/MacOS/python "$@"

代码开始

In [1]: import pandas as pd

In [2]: import numpy as np

In [3]: df = pd.read_csv('train.csv', header=0)

In [4]: cols = list(df)

In [5]: cols.insert(0, cols.pop(cols.index('Cover_Type'))) %Cover type is column I wanted to bring to column position 1 or value I'm predicting

In [6]: cols

In [7]: df = df.ix[:, cols]

In [8]: df

In [9]: forest = RandomForestClassifier(n_estimators = 100)

In [10]: forest = forest.fit(train_data[0::,1::],train_data[0::,0])

In [11]: output = forest.predict(test_data)

In [12]: train_data = df.values

In [13]: train_data

最佳答案

您正在使用第 10 行中的火车数据,该数据不可用。您稍后分配它。

先分配训练数据,然后在forest.fit中使用

关于python - 在拟合随机森林分类器时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33644341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com