RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'weight'

Hi @ptrblck, you’re quite right; this issue seems to be related to the 5-fold Randomized Search CV, so I have used error_score = ‘raise’ to enable reporting to see where the issue is exactly.

I think there is a shape issue while the RandomizedSearch 5-fold CV (cv=5 parameter used) is trying to split the data into 5 folds, and I need some guidance on how to fix this problem. I have 6 inputs required for this model.

In my output, I have printed the shape of the numpy arrays for each step to help debug, and here is the error I am encountering now:

Submitted from:/home/users/ypatra2 on node:login
Running on node node2
Allocate Gpu Units:0
2023-12-03 00:26:04.608974: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-12-03 00:26:05.588942: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 9661 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:1a:00.0, compute capability: 7.5
Current device: 0
Train Subjects: ['S16Trent', 'S10Mel', 'S19Rocco', 'S17Hayden', 'S1Ben', 'S12Nicole', 'S18Kate', 'S8Lauren', 'S20Kayne', 'S11Nick', 'S6Kat', 'S7Keisha', 'S13Roy', 'S4Ellyn', 'S2Brendan']
Test Subjects: ['S14Sam', 'S15Tom', 'S3Dan', 'S5Grace']
LeftKneeAngle LEFTKNEEANGLE

 **Before Scaling **

**X_train shape:  (230400, 6) , y_train shape:  (230400, 1) , X_test shape:  (61440, 6) , y_test shape:  (61440, 1)**

** After Scaling **

**X_train shape:  (230400, 6) , y_train shape:  (230400, 1) , X_test shape:  (61440, 6) , y_test shape:  (61440, 1)**

** Before GridSearch fit() **

**X_train_scaled shape:  (230400, 6) , y_train shape:  (230400, 1) , X_test_scaled shape:  (61440, 6) , y_test shape:  (61440, 1)**
  epoch    train_loss    valid_loss       dur
-------  ------------  ------------  --------
      1     e[36m1940.9021e[0m     e[32m1674.5093e[0m  210.9995
Traceback (most recent call last):
  File "transformer_model_1.py", line 181, in <module>
    gs.fit(X_train_scaled, y_train)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/utils/validation.py", line 63, in inner_f
    return f(*args, **kwargs)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/model_selection/_search.py", line 841, in fit
    self._run_search(evaluate_candidates)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/model_selection/_search.py", line 1635, in _run_search
    random_state=self.random_state))
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/model_selection/_search.py", line 809, in evaluate_candidates
    enumerate(cv.split(X, y, groups))))
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/joblib/parallel.py", line 1048, in __call__
    if self.dispatch_one_batch(iterator):
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/joblib/parallel.py", line 864, in dispatch_one_batch
    self._dispatch(tasks)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/joblib/parallel.py", line 782, in _dispatch
    job = self._backend.apply_async(batch, callback=cb)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 208, in apply_async
    result = ImmediateResult(func)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 572, in __init__
    self.results = batch()
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/joblib/parallel.py", line 264, in __call__
    for func, args, kwargs in self.items]
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/joblib/parallel.py", line 264, in <listcomp>
    for func, args, kwargs in self.items]
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/utils/fixes.py", line 222, in __call__
    return self.function(*args, **kwargs)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/model_selection/_validation.py", line 625, in _fit_and_score
    test_scores = _score(estimator, X_test, y_test, scorer, error_score)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/model_selection/_validation.py", line 687, in _score
    scores = scorer(estimator, X_test, y_test)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/metrics/_scorer.py", line 200, in __call__
    sample_weight=sample_weight)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/metrics/_scorer.py", line 243, in _score
    **self._kwargs)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/utils/validation.py", line 63, in inner_f
    return f(*args, **kwargs)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/metrics/_regression.py", line 336, in mean_squared_error
    y_true, y_pred, multioutput)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/metrics/_regression.py", line 88, in _check_reg_targets
    check_consistent_length(y_true, y_pred)
  File "/home/users/ypatra2/.local/lib/python3.6/site-packages/sklearn/utils/validation.py", line 320, in check_consistent_length
    " samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [46080, 90]

It is interesting to note that X_train shape was (230400,6) and 230400 divided by 5 is 46080. But i have no clue about this 90 :frowning: