# Binary disorder challenge

https://code.sololearn.com/c81vUnzCoAP6/?ref=app Can I get a better, more elegant solution than what I do here i.e any way except instantiating my x as [[0.,0.][0.,0.]]? I hate that dot(float?) instantiation. Felt like cheating.

3/1/2021 12:46:03 PM

Satrio Bayu Pradhipta11 Answers

New Answer————————————————————— you can replace everything after your second line of code with these 2 lines. from sklearn.metrics import confusion_matrix print((confusion_matrix(y_pred, y_true, labels=['1', '0']))/1) the divided by one was just a lazy way to convert my answer to a float ————————————————————— PS you can convert numpy arrays to float arrays with the dtype property. x = np.array([0, 0], [0, 0], dtype=‘f’) if you have an array that you want to turn into a float array use the astype() method. arr = arr.astype(‘f’) For reference here are the numpy dtypes: int ———————- i bool ——————- b unsigned int ——- u float ——————— f complex number - c object —————— O string ——————- S unicode string —— U void ———————- V ————————————————————— as for the long list of if statements you could us a ternary operator in a comprehension if you want to make it a one liner but it will still have the same functionality as your code so I wouldn’t say it was more elegant. —————————————————————

To make it work i needed to change the input arrays to type character. So the total code goes like: y_true = [int(x) for x in input().split()] y_pred = [int(x) for x in input().split()] import numpy as np y_true=np.array(y_true ) y_true= y_true.astype(str) y_pred=np.array(y_pred ) y_pred=y_pred.astype(str) #y_true = y_true.reshape(-1, 1) #y_pred = y_pred.reshape(-1, 1) #print(y_true.shape) from sklearn.metrics import confusion_matrix print((confusion_matrix(y_pred, y_true, labels=['1', '0']))/1)

Frank Kober the input type is character automatically in python. your list comprehension has x being casted to an int. just remove that and it will be a character already for you change it to: _____________________________ y_true = [x for x in input().split()] y_pred = [x for x in input().split()] from sklearn.metrics import confusion_matrix print((confusion_matrix(y_pred, y_true, labels=['1', '0']))/1) ______________________________

y_true = [int(x) for x in input().split()] y_pred = [int(x) for x in input().split()] from sklearn.metrics import confusion_matrix print((confusion_matrix(y_pred,y_true, labels=[1,0]))/1) It just that simple only 2 lines of code needed

I have not encountered this quiz yet, but I am wondering why you only convert the thing to an array at the very end.

Wilbur Jaywright No reason. It might work without array, but I side with err and just convert them into array because that's what the example show

what I mean is, why don’t you start with an arrary right at the beginning? They have lots of good methods for mathematical operations like you’re doing, and are easy to initialize with the right shape and preset values.

Wilbur Jaywright I'm not that comfortable with Numpy yet, so following how the data in the basic list flows is easier for me. With numpy I had to check web/tutorial just to ensure that I'm putting the right method/function. This one takes like 2-3 mins of mostly typing from phone keyboard without looking for outside sources

y_true = [(x) for x in input().split()] y_pred = [(x) for x in input().split()] import numpy as np y_true=np.array(y_true ) y_true= y_true.astype(str) y_pred=np.array(y_pred ) y_pred=y_pred.astype(str) #y_true = y_true.reshape(-1, 1) #y_pred = y_pred.reshape(-1, 1) #print(y_true.shape) from sklearn.metrics import confusion_matrix print((confusion_matrix(y_pred, y_true, labels=['1', '0']))/1) This is the solution