Numpy and Keras Flashcards

1
Q

populate an array with a sequence of numbers:

A

sequence_of_integers = np.arange(5, 12)

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

Matplotlib scatter plot

A

x = np.random.random([100])
y = np.random.random([100])
plt.scatter(x,y)

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

Populate arrays with 20 random integer from 0 to 100

A

np.random.randint(low=0,high=101,size=20)

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

Broadcasting

A

virtually expand the smaller operand to dimensions compatible

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

Multiply each cell in a vector by 3

A

x*3

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

Assign a sequence of integers from 6 to 20 (inclusive) to a NumPy array named feature.
Assign 15 values to a NumPy array named label such that:
label = (3)(feature) + 4

A

features = np.arange(6,21)
labels = (3*feature) + 4
plt.scatter(features,labels)

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

Make a Dataframe from an array of array of data and and a list of column names.

A

my_dataframe = pd.DataFrame(data=my_data, columns=my_column_names)

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

Create a new column named adjusted derived from the activity column.

A

my_dataframe[“adjusted”] = my_dataframe[“activity”] + 2

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

Create an 3x4 (3 rows x 4 columns) pandas DataFrame in which the columns are named Eleanor, Chidi, Tahani, and Jason. Populate each of the 12 cells in the DataFrame with a random integer between 0 and 100, inclusive.

A

cn = [‘Eleanor’, ‘Chidi’, ‘Tahani’, ‘Jason’]
my_data = []
for i in range(3):
my_data.append(np.random.randint(0,101,4))

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

Copying a DataFrame

A

pd.DataFrame.copy
Referencing. If you assign a DataFrame to a new variable, any change to the DataFrame or to the new variable will be reflected in the other.
Copying. If you call the pd.DataFrame.copy method, you create a true independent copy.

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

Typical hyperparameters

A

learning rate
epochs
batch_size

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

hyperparameter

A

The “knobs” that you tweak during successive runs of training a model. For example, learning rate is a hyperparameter.

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

linear model

A

A model that assigns one weight per feature to make predictions. (Linear models also incorporate a bias.) By contrast, the relationship of weights to features in deep models is not one-to-one.

A linear model uses the following formula:

y_prime= b+ sigma(w_i,x_i)

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

epoch

A

A full training pass over the entire dataset such that each example has been seen once.

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

Relationship between epoch, batch_size and training iterations

A

epoch == N/batch_size

An epoch represents N/batch size training iterations, where N is the total number of examples.

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

batch size

A

The system recalculates the model’s loss value and adjusts the model’s weights and bias after each iteration. Each iteration is the span in which the system processes one batch. For example, if the batch size is 6, then the system recalculates the model’s loss value and adjusts the model’s weights and bias after processing every 6 examples.

17
Q

An oscillating loss curve strongly suggests

A

learning rate is too high

18
Q

SGD Batch size

A

1
The batch size of a mini-batch is usually between 10 and 1000. Batch size is usually fixed during training and inference.

19
Q

TensorFlow does/does not permit dynamic batch sizes.

A

TensorFlow does permit dynamic batch sizes.

20
Q

Hyperparameter tuning

A

Training loss should steadily decrease, steeply at first, and then slowly until the slope of the loss curve approaches 0.
If the training loss does not converge, train for more epochs.
Training loss decreases too slowly: increase learning rate.
Training loss jumps around: decrease learning rate.
First, try large batch size values. Then, decrease the batch size until you see degradation.
Very large number of examples: reduce batch size to enable a batch to fit into memory.

21
Q

ideal combination of hyperparameters is

A

ideal combination of hyperparameters is data dependent: always experiment

22
Q

Pivot a table in pandas

A

data[“hours_since_admitted_rounded”] = round(data[“hours_since_admitted”])
pivoted = data.pivot_table(columns=”component_name”,values=”z_score_ord_num_value”, index=”hours_since_admitted_rounded”, fill_value=0)
pivoted.head(10)