Exam 2 Flash Cards

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/99

encourage image

There's no tags or description

Looks like no tags are added yet.

100 Terms

1
New cards

ndarray

NumPy's array. A grid of numbers that are all the same type.

2
New cards

.shape

(rows, columns). Example: 2 rows, 3 columns → (2, 3)

3
New cards

.ndim

How many dimensions. One row = 1. A grid = 2.

4
New cards

dtype

The type of the numbers inside, like int64 or float32.

5
New cards

np.arange(8)

[0 1 2 3 4 5 6 7]. Counts from 0, stops BEFORE 8.

6
New cards

.reshape(2, 3)

Folds the numbers into 2 rows and 3 columns. Rows × columns must equal the total.

7
New cards

arr[r, c] vs arr[r]

arr[r, c] = one number at row r, column c. arr[r] = the whole row. Start counting at 0.

8
New cards

Slice start:stop:step

Grabs a range. The stop number is NOT included.

9
New cards

arr[:, 1]

Column 1 from every row.

10
New cards

arr[arr > 2]

Keeps only numbers bigger than 2. Gives back a flat list.

11
New cards

.sum(axis=0)

Adds DOWN each column. One answer per column.

12
New cards

.sum(axis=1)

Adds ACROSS each row. One answer per row.

13
New cards

ndarray vs list (types)

Array = one type only. List = can mix types.

14
New cards

[1,2,3]2 vs array2

List repeats: [1,2,3,1,2,3]. Array multiplies: [2 4 6].

15
New cards

np.split / hsplit / vsplit

Breaks an array apart. Gives back a LIST, not an array.

16
New cards

Figure

The frame. The whole image.

17
New cards

Axes

One chart inside the frame.

18
New cards

plt.subplots(2, 3)

Makes 2 rows × 3 columns = 6 charts.

19
New cards

Picking a chart in a 2×2 grid

ax[row, col]. Start at 0. ax[1, 0] = bottom-left.

20
New cards

Picking a chart in plt.subplots(1, 3)

Only one row, so use one number: ax[0], ax[1], ax[2].

21
New cards

Class rule for plt

Only use plt for plt.subplots() and plt.style.use(). Everything else uses ax or fig.

22
New cards

sharex / sharey

All charts use the same x (or y) number range, so they're easy to compare.

23
New cards

ax.set_title vs fig.suptitle

ax.set_title = title for one chart. fig.suptitle = title for the whole figure.

24
New cards

Legend shows nothing

You forgot label='…' when you plotted the data.

25
New cards

Line plot

Shows change over time. ax.plot()

26
New cards

Scatter plot

Shows how two number columns relate. ax.scatter()

27
New cards

Bar chart

Compares amounts between categories. ax.bar()

28
New cards

Pie chart

Shows parts of a whole (percents). ax.pie()

29
New cards

Histogram / box / violin

Show how values are spread out. Box plots also show outliers.

30
New cards

Plotting order

Style → subplots → plot data → labels and legend → savefig (last).

31
New cards

pandas

Package for tables with mixed data types. Built on NumPy.

32
New cards

Series

One column with labels.

33
New cards

DataFrame

A whole table. Many Series side by side.

34
New cards

pd vs df

pd = pandas itself (pd.read_csv). df = your table (df.head()).

35
New cards

pd.read_csv('file.csv')

Loads a CSV file into a DataFrame. First line becomes the column names.

36
New cards

skiprows=2

Skips the first 2 lines of the file.

37
New cards

df.info()

Shows column names, data types, and missing counts. No print() needed.

38
New cards

df['col']

Grabs ONE column. Gives a Series.

39
New cards

df[['a', 'b']]

Grabs MANY columns. Gives a DataFrame.

40
New cards

.iloc[]

Picks by position number. Slice end NOT included.

41
New cards

.loc[]

Picks by label or name. Slice end IS included.

42
New cards

df.loc[:4] vs df.iloc[:4]

loc = 5 rows (0–4). iloc = 4 rows (0–3).

43
New cards

Filtering rows

df[df['col'] > x] keeps only rows that pass the test.

44
New cards

df['old'] = … vs df['new'] = …

Old name = replaces that column. New name = adds a new column.

45
New cards

sort_values vs sort_index

sort_values(by='col') = sort by a column. sort_index() = sort by row labels.

46
New cards

Does sort_values change df?

No. You must save it: df = df.sort_values(…). Same for drop and dropna.

47
New cards

df.groupby('col')

Splits rows into groups. Does nothing until you add .mean(), .sum(), etc.

48
New cards

Data wrangling

Cleaning messy data so you can use it.

49
New cards

Cross sectional data

Many sources, one time. (All students' grades this semester.)

50
New cards

Time series data

One source, many times. (One class's enrollment each year.)

51
New cards

Panel data

Many sources, many times. (All students' grades every semester.)

52
New cards

df.drop_duplicates()

Removes repeated rows. Do it early, before picking columns.

53
New cards

Malformed data

Data typed in wrong. Example: a letter in a number column, or 'peter' in a yes/no column.

54
New cards

nunique() vs unique()

nunique() = how many different values. unique() = the list of them.

55
New cards

isnull().sum()

Counts missing values in each column.

56
New cards

df.dropna()

Deletes every row that has a missing value. Save it: df = df.dropna().

57
New cards

df.dropna(axis=1)

Deletes every column that has a missing value.

58
New cards

When to use dropna

After you pick your columns.

59
New cards

Box plot

Box = middle 50%. Line = median. Whiskers = normal range. Dots outside = outliers.

60
New cards

Outliers (this class)

Leave them alone.

61
New cards

Machine learning

Computers that learn from examples and get better with experience. Part of AI.

62
New cards

Algorithm vs model

Algorithm = the learning method. Model = what it learned.

63
New cards

Features (X)

The clues. The input columns used to make a guess.

64
New cards

Target (y)

The answer. The one column you're trying to guess.

65
New cards

Training

Showing the model clues AND answers so it can learn.

66
New cards

Supervised learning

Learns from examples that have answers (labels).

67
New cards

Unsupervised learning

No answers given. Finds groups on its own (clustering).

68
New cards

Reinforcement learning

Learns by trying actions and chasing a reward. (Self-driving car.)

69
New cards

ML process

1) Clean, split X/y, split train/test, scale. 2) Train. 3) Predict and check.

70
New cards

X = df.drop(columns='Species'), y = df['Species']

X = all columns except the answer. y = just the answer column.

71
New cards

train_test_split order

X_train, X_test, y_train, y_test

72
New cards

test_size=0.25

25% for testing, 75% for training.

73
New cards

stratify=y

Keeps the same mix of labels in the training and testing sets.

74
New cards

Why scale?

So big numbers (like grams) don't drown out small numbers (like years).

75
New cards

StandardScaler rules

Fit on X_train only. Transform X_train and X_test. Never scale y.

76
New cards

Re-wrap after scaling

The scaler gives back a plain array, so put it back in pd.DataFrame to keep column names.

77
New cards

KNN

Guesses by majority vote of the k closest examples.

78
New cards

How KNN predicts

Measure distance to every example → sort → take the k closest → most common label wins.

79
New cards

Effect of k

Changing k changes how many neighbors vote, which can change the answer.

80
New cards

.fit(X_train, y_train)

Trains the model.

81
New cards

.predict(X_test)

Makes guesses (y_pred).

82
New cards

.score(X_test, y_test)

Gives accuracy: how many guesses were right (0 to 1).

83
New cards

ANN

Artificial neural network. Layers of nodes connected like brain neurons.

84
New cards

Node

One circle (one neuron) in the network.

85
New cards

Weight

How much a connection counts. Changed during training.

86
New cards

Activation function

Decides what a node sends out.

87
New cards

Input / hidden / output layers

Input = features in. Output = answer out. Hidden = the mystery middle.

88
New cards

Perceptron

ONE artificial neuron.

89
New cards

MLP

Many perceptrons in layers. Signals only go forward.

90
New cards

Loss function

Measures how wrong the model is. Goal: make it small.

91
New cards

Backpropagation

Sends info backward to fix the weights so the model gets less wrong.

92
New cards

Underfit

Too simple. Misses the pattern.

93
New cards

Overfit

Memorized the training data. Bad on new data.

94
New cards

hidden_layer_sizes=(10, 10, 10)

3 hidden layers, 10 nodes each.

95
New cards

max_iter=1000

How many training rounds to adjust the weights.

96
New cards

Confusion matrix

Grid of real answers vs guesses. Diagonal = correct. Everything else = mistakes.

97
New cards

Precision

When it guessed "yes," how often was it right? TP / (TP + FP)

98
New cards

Recall

Of all the real "yes" ones, how many did it find? TP / (TP + FN)

99
New cards

F1-score

Precision and recall combined into one score.

100
New cards

Accuracy

Right guesses ÷ all guesses.