« first day (3893 days earlier)      last day (1038 days later) » 

1:34 AM
cabbage
 
 
2 hours later…
3:08 AM
can anyone see a reason why code is slow?
 
3:38 AM
it looks like it should be possible to do it in O(n log n) but I cant see how
 
 
4 hours later…
7:08 AM
@user14 Please read our chat rules about asking questions :D
 
7:35 AM
and also Stack Overflow's
 
8:01 AM
Hi guys, I have a question regarding on how to set the x axis labels .
In my case my x axis is the Datetime stamps which are in YYYY-MM-DD: HH:MM:SS format.. But I only want to show the hours. How do I do that?
 
I don't know the answer regardless, but please clarify which library you are talking about - matplotlib?
 
matplot lib
I just want to make the labels different
Not affect the plot in anyway
 
quick googling gets me stackoverflow.com/questions/14946371/… which should at least suggest what more to google
 
thank
thanks*
 
DOT
9:28 AM
While doing kfold or stratifiedcv, how to get the indices of misclassified or classified folds. I am able to get misclassified folds, but not able to get their indices. This question has no answer in stackoverflow... stackoverflow.com/questions/66686327/… . So I created a new one that need only indices....
and this is the link to the new question, stackoverflow.com/questions/67956643/… Even though it is new, it has no answer for the previous question that asked 2 months ago
 
I'm not familiar with the specific method here, but what is the output of fold_pred? I'd suggest it's a 1D list/array/Series of values?
My suspicion is that both you and the previous asker have fallen into the trap of making this way too problem-specific and really you just want the indices of an array that meet some criteria
 
10:05 AM
cbg
 
DOT
10:27 AM
fold_pred = [pred[j] for i, j in skf.split(X,y)]
fold_pred

[array([0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0]),
array([0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0]),
array([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1]),
array([0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]),
array([0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0]),
array([0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0]),
array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]),
array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]),
array([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0]),
 
So now you want the index of 0s?
Putting arrays into a list like that is a mistake, you're missing the power of numpy 2D arrays / a matrix
 
DOT
i want indices of each fold... is it possible?
 
Can you show me the expected output please?
 
DOT
I have a dataframe X_train and X_test, suppose 100 samples... when I use stratified 5 fold c.v, it is making 5 folds... I just want to know which instances are misclassified in that 100 samples while doing cross-validation.
 
You keep talking about folds but I want to know what the output looks like. I know about k-fold cross validation but I don't know what you actually want as an output
I'm on board with fold_pred. What do you want from that specific example?
 
DOT
10:39 AM
Sprouts... suppose, X_missclassified.index = X.index[anymethod.sample_indices_]. Is there any method to get index of misclassified... So the output is a dataframe that only has misclassified instances while doing cross validation. Melon
 
Are you looking for the list.index method, perhaps?
 
I just want to see the expected output :'( We've got half of the way there
 
DOT
@roganjosh sprouts.. I will post it now..
col1 col2 col3 col4 target
13 0 1 0 0 0
14 0 1 0 0 0
18 0 1 0 0 0
22 0 1 0 0 0
where input has 100 instances, 4 are misclassified (index number 13,14,18 and 22) while doing CV
@MisterMiyagi is it possible to use it while doing CV
 
11:16 AM
I spotted a walrus in the wild and it was even worse than I anticipated :(
I kid you not, the code would've been shorter without the walrus
 
the only place I can think of where a walrus can make the code longer is (a:=a+1)
 
str(cell_value) if (cell_value := cell.value) is not None else ""
 
I was not expecting that, is this from a blog post / question or an actual code base?
 
From an answer on SO
 
This solution uses the newly introduced assignment expressions aka "walrus operator": I think may have found what you are referring to
for once google actually worked for code snippet search
 
 
1 hour later…
12:58 PM
There's a word I'm trying to think of but it's eluding me. It's something like the opposite of claustrophobia, but it's the tendency for a creature to want to be in contact with physical objects (like an insect that wants to burrow into a dirt and be totally compacted in). It drives a lot of behaviour in insects and it's a "philia" word, but my searches are failing :/
@DOT I've had a go with this but I don't think I'm connecting the dots correctly
Hmm, maybe I was wrong. "Thigmotaxis" seems to be what I was looking for. That was a pain to search!
 
DOT
1:30 PM
I tried and got the index in each fold.. But unable to map each fold with predicted fold... # Generate the training/testing visualizations for each CV split
for ii, (tr, tt) in enumerate(kfold.split(X=X_train, y=Y_train, groups=None)):
# Fill in indices with the training/test groups
indices = np.array([np.nan] * len(X_train))
indices[tt] = 1
indices[tr] = 0
fold_indices.append(indices)
 
DOT
2:13 PM
Now the problem is very simple.. But I am newbie in Python.. So I wonder any good method is there to do so... Fold1_df:

is_in_test_fold real_target
0 1 0
1 1 0
2 1 1
3 0 0
4 0 0
5 1 1


fold1_preds:

[0,1,0,0]
Now I am just want to map fold1_preds where it is 1 in the column "is_in_test_fold"... But to be done in sequentially...
 
I don't think you want to "map", you want to "filter"
That might seem like I'm being pedantic over the wording, but it might be what's causing you issues
DataFrames maintain order for filtering, so you would get a "sequential" result
 
2:42 PM
Given a list of numpy boolean masks, is there an easy way to & them all together?
If not, I have to decide between using functools.reduce and rewriting the code
 
@Aran-Fey you mean like vstack and hstack?
 
2:57 PM
No, I mean like masks[0] & masks[1] & masks[2] & ...
 
The list comp is not a great solution, but it comes from another answer. I personally think that DOT has this
@Aran-Fey in which case, no, I don't think I know of a way of doing that. Maybe if you had the masks in a 2D array...
Then you could sum it by row
 
I opted for the rewrite and ended up with this (haven't tested it yet though)
 
 
1 hour later…
4:10 PM
In [225]: rng = np.random.default_rng()
     ...: masks = rng.random((3, 4)) < 0.5

In [226]: masks
Out[226]:
array([[False,  True,  True,  True],
       [False, False, False,  True],
       [ True,  True,  True,  True]])

In [227]: np.logical_and(*masks)
Out[227]: array([False, False, False,  True])

In [228]: np.logical_or(*masks)
Out[228]: array([False,  True,  True,  True])
@Aran-Fey ^
 
Oh, so easy, thanks. I was googling for stuff like "intersection"
 
it's also a ufunc so it has reduce of its own, if you need more fancy things, like reducing along a non-trivial axis
In [230]: np.logical_and.reduce(masks)
Out[230]: array([False, False, False,  True])

In [231]: np.logical_and.reduce(masks, axis=1)
Out[231]: array([False, False, False])

In [232]: np.logical_or.reduce(masks, axis=1)
Out[232]: array([ True,  True,  True])
 
Interesting. I'll have to read up on ufuncs, haven't heard that term before
 
It's short for "universal function", it's a core numpy thing numpy.org/devdocs/reference/ufuncs.html
there are also gufuncs (mostly in scipy? not sure) with more general signatures I think (generalized ufuncs or something)
 
5:08 PM
@Aran-Fey "My goal is to find out whether a given puzzle has a unique solution or not." Sorry, I don't know how to tackle that problem, apart from brute force. I guess it could be translated into an Exact Cover problem.
Knuth's Algorithm X handles Exact Cover problems, and finds all solutions, but it's essentially just a way of organising a brute force search, so any solutions that take advantage of the structure of the problem generally out-perform Algorithm X. But it's popular for stuff like Sudoku, polyomino packing, and map colouring
My guess is that an efficient solution would take advantage of how the row clues and column clues interact. There might be a clever way to encode that into an Exact Cover approach...
If you already have one solution, there might be ways to transform it into other solutions. Anyway, I think this could be a good question for Math.SE. But you probably need to mention at least one attempt you've made at solving it. Otherwise, there's a high probability that it'll get closed.
 
cbg, all. Anyone clue me in on why import dbm.gnu would result in ModuleNotFoundError: No module named '_gdbm'?
Even better, please tell me how to fix the issue.
 
FWIW, I posted Python code that uses Algorithm X here: math.stackexchange.com/a/1619332/207316 It uses it to place the trominoes, and uses it again to colour them.
@holdenweb Sounds like a broken installation. Sorry, I don't know how to fix it. But answerers probably need to know what OS this is on, and where you installed it from, and if you installed it into a virtual environment. Etc.
Ah, I see it's supposed to be a standard module...
 
5:32 PM
Yeah, but something's screwy somewhere.
Never mind, doubtless inspiration will arrive in due course. This isn;t for work so I can let it stew.
 
@PM2Ring Hmm, I don't quite see how it could be transformed into an exact cover problem. But if it's ultimately still a brute force search, it doesn't really matter anyway. I need to find all solutions, which means I have to try all combinations
So it doesn't matter if the algorithm finds the solutions early, the amount of time it takes to complete is still the same
 
5:52 PM
@PM2Ring Annoyingly the error has now disappeared on all environments without my having any idea of having done anything to fix it. Hate that!
 
6:29 PM
Cabbage!
 
6:48 PM
@Aran-Fey I'm not quite sure how to convert into an Exact Cover problem, either. ;) I have used Exact Cover to complete Latin Squares, which also have vertical & horizontal constraints, but that was a few years ago. Nonograms are NP-complete, so there's no general solution better than brute force (as far as we know), but of course various heuristics can be useful.
FWIW, there are a couple of SO questions about them, eg stackoverflow.com/q/813366/4014959 Also see math.stackexchange.com/search?q=nonogram
They're also popular on Puzzling.SE: puzzling.stackexchange.com/search?q=nonogram There might be some useful info there...
 
Oh man, Andras already told me they were called Nonograms but I didn't realize they were so popular. I should've googled more
 
 
2 hours later…
9:02 PM
Can anyone please explain to my simply what an Walrus Operator is?
 
?
 
It's an assignment expression, as opposed to an assignment statement. The difference being that statements are top-level things whereas expressions can be nested into other expressions.
 
ok
 
The most obvious use-case is that an assignment expression / walrus can be used inside an if statement: if (fraction := a /b) > 0: print(f"{fraction} is positive")
 
Nice and simple, arigatogo MisterMiyagi!
 
9:14 PM
I found a Nonogram validator written in C++, and the combination of C++ and lack of comments is making it really hard to decipher. Spent 2 minutes wondering "What's this function parameter??" only to realize that's where the function saves its results :|
Someone should tell C++ that parameters are for inputs, not for outputs
 
Every time I read a library in C++, the lack of comments and terrible variable names give an air of "duh. If you don't follow this, don't be here". Now apparently the language itself conspires against you.
 
9:33 PM
It seems like C++ folks wouldn't have a problem with *-imports either. There are boatloads of variables that magically exist and I have no idea why
 
yeah, implicit self sucks
 
And so does #include
 

« first day (3893 days earlier)      last day (1038 days later) »