@kmt_kni

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

sklearnの並列処理でDataConversionWarning

解決したいこと

sklearnを並列処理で動かす実験をしています。
1)
Parallel(n_jobs=1)(
で起動した場合は、何のエラーもなく動くのですが、
2)
Parallel(n_jobs=-1)( にして並列処理にすると
DataConversionWarning:が発生します。

そのワーニングが言う通り、shapeで(n_samples,)の形状にしたり、y_dataがViewの場合はcopyにもしたのですがワーニングは出力されるので、その原因がよく分かりません。
解決方法を教えて下さい。

発生している問題・エラー

../python3.11/site-packages/sklearn/preprocessing/_label.py:129: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  y = column_or_1d(y, dtype=self.classes_.dtype, warn=True)

該当するソースコード

   並列処理部
  ...
    Xs_train, Xs_test, ys_train, ys_test = custom_train_test_split(X_train, y_train, test_size=test_size, random_state=42)
    ys_train = ys_train.copy()
    ys_test = ys_test.copy()
    ys_train = np.ascontiguousarray(ys_train.reshape(-1,))
    ys_train = check_y_shape(model_name, store_id, ys_train, loc=f'{location()}')	
    
    model = get_model_instance(model_name, store_id)
    
    ys_train = check_y_shape(model_name, store_id, ys_train)
    model.fit(Xs_train, ys_train)	


### 自分で試したこと
check_y_shape()ys_trainの形状が(n, 1)の場合に (n, )にshapeしviewならばcopyし直す処理です
0 likes

No Answers yet.

Your answer might help someone💌