簡體   English   中英

輸入適用於某些sklearn模型,但不適用於sklearn.linear和sklearn.ensemble中的其他模型

[英]Inputs working with some sklearn models but not other models in sklearn.linear and sklearn.ensemble

_train_weather.values :  [[ 0.61818182  0.81645199  0.6679803  ...,  0.          0.          1.        ]
 [ 0.61664841  0.80064403  0.65073892 ...,  0.          0.          0.        ]
 [ 0.58291347  0.80679157  0.62783251 ...,  0.          0.          0.        ]
 ..., 
 [ 0.65914567  0.52019906  0.59975369 ...,  1.          0.          0.        ]
 [ 0.56232202  0.37558548  0.47980296 ...,  0.          1.          0.        ]
 [ 0.51829135  0.35626464  0.42832512 ...,  0.          0.          1.              ]]


_train_traffic['walkin_in'].values :  [[ 0.  0.  0. ...,  0.  0.  0.]
[ 0.  0.  0. ...,  0.  0.  0.]
[ 0.  0.  0. ...,  0.  0.  0.]
..., 
[ 0.  0.  0. ...,  0.  0.  0.]
[ 0.  0.  0. ...,  0.  0.  0.]
[ 0.  0.  0. ...,  0.  0.  0.]]


_test_weather.values :  [[ 0.3388828   0.50497658  0.341133   ...,  0.          0.          0.        ]
[ 0.27426068  0.4809719   0.30591133 ...,  0.          0.          0.        ]
[ 0.28368018  0.42681499  0.26600985 ...,  0.          0.          0.        ]
..., 
[ 0.732092    0.71516393  0.69482759 ...,  1.          0.          0.        ]
[ 0.74348302  0.70257611  0.6817734  ...,  0.          1.          0.        ]
[ 0.75465498  0.69642857  0.70862069 ...,  0.          0.          1.        ]]

我有如上所述的值數組。 我正在使用_train_weather.values(X)和_train_traffic ['walkin_in']。values(Y)進行訓練。 我預測_test_weather.values。

數據幀類似於上面。

我可以使用這些輸入來預測使用sklearn中的某些模型,例如MLP,RANSAC,Lasso,Ridge,LassoLars,RandomForestRegressor等,但是有些模型不起作用。

這是不起作用的列表:

SGD回歸器Adaboost回歸器裝袋回歸器Lars GradientBoosting回歸器ARD回歸BayesianRidge Huber回歸器

同樣,ElasticNet也可以工作,但不是ElasticNetCV,如果LassoCV無法工作,這也適用於Lasso。

它們提供以下錯誤:

Traceback (most recent call last):
File "run_seq_predictor.py", line 519, in <module>
run(args.conf, train, test_model, test_MLP_reg, offset, verbose, weeks,   daily, write_to_isio, filter_abnormal, threshold)
File "run_seq_predictor.py", line 420, in run
clf.fit(_train_weather.values, _train_traffic['walkin_in'].values)
File "/usr/local/lib/python2.7/site-packages/sklearn/ensemble/bagging.py", line 248, in fit
return self._fit(X, y, self.max_samples, sample_weight=sample_weight)
File "/usr/local/lib/python2.7/site-packages/sklearn/ensemble/bagging.py", line 284, in _fit
X, y = check_X_y(X, y, ['csr', 'csc'])
File "/usr/local/lib/python2.7/site-packages/sklearn/utils/validation.py", line 526, in check_X_y
y = column_or_1d(y, warn=True)
File "/usr/local/lib/python2.7/site-packages/sklearn/utils/validation.py", line 562, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (253, 56)

有人可以解釋一下為什么只有某些模型會提供上述錯誤,而其他模型卻完全正常嗎?

您的因變量是多變量的,並非所有模型都可以對其建模。 如果您閱讀了RANSAC,Lasso,Ridge,LassoLars,RandomForestRegressor等文檔,那么您會在fit函數下看到類似以下的內容

y : array-like, shape = [n_samples] or [n_samples, n_targets]

至於您列出的其他位置,例如GradientBoostingRegressor

y : array-like, shape = [n_samples]

這就是為什么您得到錯誤。 如果您提供有關因變量的更多詳細信息,我很樂意編輯答案。 您的數據看起來可能是一鍵編碼的...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM