我正在嘗試創建一個流水線來幫助我處理一些數據:輸入平均值,縮放數據,然後擬合迴歸器。流水線說明錯誤「輸入包含NaN」
我在Imputer上遇到了一些麻煩,可能會使用它。我知道我的數據包含NaN;但是當我嘗試開關輸入他們一個管道里,我得到一個ValueError:
Traceback (most recent call last):
File "<ipython-input-124-8517b294cb64>", line 1, in <module>
modelBuild(df)
File "C:/Users/tmori/Google Drive/Projects/Product Dimension Accuracy/Qubert_PredictiveModel/qubert_predictive_model.py", line 81, in modelBuild
clf_x = pipeline.fit_transform(df[['OverallHeight-ToptoBottom', 'OverallDepth-FronttoBack']], df['OverallWidth-SidetoSide'])
File "C:\Program Files\Anaconda\lib\site-packages\sklearn\pipeline.py", line 303, in fit_transform
return last_step.fit_transform(Xt, y, **fit_params)
File "C:\Program Files\Anaconda\lib\site-packages\sklearn\base.py", line 497, in fit_transform
return self.fit(X, y, **fit_params).transform(X)
File "C:\Program Files\Anaconda\lib\site-packages\sklearn\ensemble\forest.py", line 248, in fit
y = check_array(y, accept_sparse='csc', ensure_2d=False, dtype=None)
File "C:\Program Files\Anaconda\lib\site-packages\sklearn\utils\validation.py", line 407, in check_array
_assert_all_finite(array)
File "C:\Program Files\Anaconda\lib\site-packages\sklearn\utils\validation.py", line 58, in _assert_all_finite
" or a value too large for %r." % X.dtype)
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
我的代碼看起來像這樣至今:
def modelBuild(df):
imp = Imputer()
scl = StandardScaler()
clf = RandomForestRegressor()
pipeline = Pipeline([('imputer', imp),
('scaler', scl),
('clf', clf)])
clf_x = pipeline.fit_transform(df[['OverallHeight-ToptoBottom', 'OverallDepth-FronttoBack']], df['OverallWidth-SidetoSide'])
和數據幀數據的例子:
StagName OverallDepth-FronttoBack OverallHeight-ToptoBottom \
PtagPrSKU
AABP1004 NaN 48.0
AAI2179 28.0 32.0
AAI2180 28.0 32.0
AAI2181 36.0 32.0
AAI2182 36.0 32.0
StagName OverallWidth-SidetoSide
PtagPrSKU
AABP1004 64.0
AAI2179 55.0
AAI2180 55.0
AAI2181 71.0
AAI2182 71.0
我非常確定我只是使用了Imputer錯誤,但我無法爲我的生活尋找到哪裏。
在此先感謝您的幫助!
最佳, 湯姆
代碼中的問題是數據框中的行PtagPrSKU。看到我的答案。 – sera