Closed windowshopr closed 1 year ago
I've figured it out! Sort of.
The problem is due to trying to employ the sample_weight=sample_weights,
line, for some reason the weights are not working correctly or something, and it screws up in each scoring metric. It works fine when I comment out/don't use sample_weight
's in each individual scoring metric.
I've tried using both compute_class_weight
and compute_sample_weight
but the same result with both.
Maybe I'm not using those properly, and really, I think if you set the average
parameter in the scoring functions to 'weighted'
it does the same thing? Not sure. But when I don't use sample weights, it works.
I'll close this issue for now. If someone knows what's going on here, let me know.
Thanks!!!
Intro
I am attempting to use a custom scoring function that returns the average of several scikit-learn scoring metrics (as a Proof of Concept idea). The code I have now (which I will post below, along with a link to the dataset in parquet format that I'm using for reproducibility) returns the following traceback (sorry for the length of it, but figured it's best to be thorough):
Context of the issue
This error typically suggests that the shapes of my data (
X_train.shape[0]
andy_train.shape[0]
) are different, however this is not the case as seen from this printout:I found a similar issue #1148 where they suggested downgrading the scikit-learn version to
0.23.2
, which I have already attempted, as well as running it with the latest version1.0.2
. Another issue #1147 turned me on to the idea that maybe mymax_eval_time_mins=5
was too short (as pipelines that take too long return a-float(inf)
as default), so I up'd it to20
which is overkill for this dataset just to be safe, but that didn't help either. Note, I am also usingcv=TimeSeriesSplit(n_splits=2)
but this doesn't cause a problem.To try and narrow this issue down a bit, I've tried changing the
scoring=my_custom_scorer,
parameter to a known metric ofscoring='balanced_accuracy',
to ensure the code runs, which it DOES, so I know it's something to do with my custom scoring metric.To help even further, you'll see in my code below that I have commented out all of the other scoring metrics and I'm trying to simply make use of sklearn's
balanced_accuracy_score
function, so I'm NOT doing the proposed "average of several metrics" thing for now because I need to figure out how to make it "work" with just one first. So essentially, instead of definingscoring='balanced_accuracy',
, I'm doing:...which sort of SHOULD be the same thing?
I've commented the code well and reduced it to a minimal working example, so long as you are using the same dataset, which you can download in
parquet
format from my Google Drive link here (size is 32.9 Mb):https://drive.google.com/file/d/1I1ZwnxsSv5iDna9nmSduW9T0UWMQzaIt/view?usp=sharing
Process to reproduce the issue
data
in the same location as this script. So you should havethis_script.py
and thedata
folder in the same directory.Expected result
Training shouldn't crash.
Current result
I've narrowed it down to the custom scoring metric. The code runs when
scoring='balanced_accuracy'
is set, but not withscoring=my_custom_metric
. The dataset is free ofinf
's and-inf
's, and there are nonan
's, which you can see once the.describe()
function is saved to an excel document.Possible fix
Not sure yet, but I've tried to mitigate
inf
in thebalanced_accuracy_score
function by implementing:...but this didn't solve it either. Again, the code works if not using the custom scoring metric as defined in the code.
To sum, I'm running Python 3.7.9, Windows 10, scikit-learn==1.0.2, and tpot==0.11.7.
Here is the code: