亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

盡管已刪除,但 Python 隨機森林回歸器仍對 nan 值出錯

盡管已刪除,但 Python 隨機森林回歸器仍對 nan 值出錯

慕尼黑5688855 2021-12-17 14:47:33
我有一個干凈的數據集,其 nan 值為零,但我繼續在回歸器上遇到相同的錯誤。我的框架叫做 new_player_data我試過找到任何list(new_player_data.where(new_player_data.isna()).count() > 0)返回[假,假,假,假,假,假]大約兩百次。我認為可能有一些太大的浮動。我試過這個:for i in new_player_data.columns[:]:    if new_player_data[i].dtype == float:        new_player_data[i] = round(new_player_data[i],2)無論我得到什么:regressor.fit(X_train, y_train)  ---------------------------------------------------------------------------ValueError                                Traceback (most recent call last)<ipython-input-327-3a664017ddaa> in <module>----> 1 regressor.fit(X_train, y_train)/anaconda3/lib/python3.7/site-packages/sklearn/ensemble/forest.py in fit(self, X, y, sample_weight)    248     249         # Validate or convert input data--> 250         X = check_array(X, accept_sparse="csc", dtype=DTYPE)    251         y = check_array(y, accept_sparse='csc', ensure_2d=False, dtype=None)    252         if sample_weight is not None:/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)    571         if force_all_finite:    572             _assert_all_finite(array,--> 573                                allow_nan=force_all_finite == 'allow-nan')    574     575     shape_repr = _shape_repr(array.shape)/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in _assert_all_finite(X, allow_nan)     54                 not allow_nan and not np.isfinite(X).all()):     55             type_err = 'infinity' if allow_nan else 'NaN, infinity'---> 56             raise ValueError(msg_err.format(type_err, X.dtype))     57      58 ValueError: Input contains NaN, infinity or a value too large for dtype('float32').關于我還可以在這里檢查什么的任何想法?虧本
查看完整描述

1 回答

?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

發現它是 inf 值,通過


infs = np.where(np.isinf(new_player_data))

infs


out: (array([ 261, 1162, 1190, 1339, 1365, 1451, 1656, 1736, 1878, 1954, 2189,

    2299, 2741, 3137, 3162, 3799, 3821, 3881, 4305]),

 array([ 3, 43, 43,  3, 43, 43, 43, 43, 43, 43, 23, 43,  3, 43, 43, 43,  3,

    23, 43]))

然后我就這樣替換了它們


pd.options.mode.use_inf_as_na = True

infs = np.where(np.isinf(new_player_data))

infs

out: (array([], dtype=int64), array([], dtype=int64))


查看完整回答
反對 回復 2021-12-17
  • 1 回答
  • 0 關注
  • 276 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號