我正在尝试在 pandas 数据帧上运行随机森林。我知道数据框中没有空值或无穷大,但当我拟合模型时不断收到 ValueError 。大概这是因为我有 flaot64 列而不是 float32;我还有很多 bool 和 int 类型的列。有没有办法将所有 float 列更改为 float32?
我尝试重写 CSV,并且相对确定问题不在于此。我以前从未在 float64 上运行随机森林时遇到过问题,所以我不确定这次出了什么问题。
labels = electric['electric_ratio']
electric = electric[[x for x in electric.columns if x != 'electric_ratio']]
electric_list = electric.columns
first_train, first_test, train_labels, test_labels = train_test_split(electric, labels)
rf = RandomForestRegressor(n_estimators = 1000, random_state=88)
rf_1 = rf.fit(first_train, train_labels)
Run Code Online (Sandbox Code Playgroud)
我希望这适合模型,但始终得到
ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
Run Code Online (Sandbox Code Playgroud) python machine-learning pandas random-forest jupyter-notebook