r/learnpython • • 11d ago

Help: non-reproducible code

I am working on a project where I need to cluster large amount of data and do a dimensionality reduction for the purpose of picking data points near the centroids. I finished this and chose my data points near the centroids (I have now invested time and resources into my experimentation with this part of my project) and later came back to my code and re-ran it and it gave me centroids in a different location and different clustering results. I thought maybe I forgot to assign a random_state for one of my techniques (either clustering or dimensionality reduction) but I had indeed defined them, and if I run my code again it reproducibly gives me the same results that it gave me when I ran my code the second time around (still different than what I have based my physical experimentation on).

I wondered then if I had changed some part of the code so I went back to an old version of my file that I had saved awhile ago because I was afraid of this very thing happening - and it gives me the same results as above (still not the original clustering results). I literally haven't changed the old code at all so I have no idea what happened. Is it possible at all that some other factor is involved? This is my first time using python for a project and I don't have any formal training and I have no idea what to do since my project is based on some computational work that apparently cannot be reproduced

4 Upvotes

11 comments sorted by

View all comments

4

u/JaguarMammoth6231 11d ago

Are you sure you have the right file open in your editor? Are you sure you're running the file you think you are?

2

u/ImprovementOk6448 11d ago

Thanks, turns out I had accidentally replaced my file with another file of the same name by running my file-generating code again with some changes awhile back. Luckily I had saved a backup in my "old files" folder and had to run each of those until it gave me my old results...

1

u/StevenJOwens 11d ago

What u/JaguarMammoth6231 says. I've been programming for over 30 years and this still happens from time to time, so double and triple check.