Usefull functions Flashcards

1
Q

1) write number to file(file_name)

2) write array to file(file_name)

A

1)
def write_answer_(num,file_name):
with open(file_name,”w”) as fout:
fout.write(str(num))

2)
def write_answer_arr(scores_,file_name):
with open(file_name, “w”) as fout:
fout.write(“ “.join([str(num) for num in scores_]))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

map preds array of (0, 1, 2)s into mapped_preds array of (2, 0, 1)s

A
mapping = {0 : 2, 1: 0, 2: 1}
mapped_preds = [mapping[pred] for pred in preds]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

count number of lines in file

A

1) num_lines = sum(1 for line in open(‘myfile.txt’))

2) num_lines = len(list(open(‘myfile.txt’)))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

change package in conda

A

conda install scikit-learn=0.17

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create bootstrap sample

A
def get_bootstrap_samples(data, n_samples):
    indices = np.random.randint(0, len(data), (n_samples, len(data)))
    samples = data[indices]
    return samples
How well did you know this?
1
Not at all
2
3
4
5
Perfectly