Numpy Flashcards

1
Q

Define an array at numpy

A

import numpy as np

a=np.array([0,1,2,4])

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

Create a multidimensional array in numpy

A

b = np.array([[0, 1, 2], [3, 4, 5]]) # 2 x 3 array

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

How to create a numpy array in one move?

A

np.arange(10)

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

How to create an array with defined number of points between a range of numbers?

A

c = np.linspace(0, 1, 6)

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

Create

a) An array of ones
b) An array of zeros
c) A diagonal array

A
a = np.ones((3, 3))  # reminder: (3, 3) is a tuple
b = np.zeros((2, 2)
c = np.eye(3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which is the most common data type in numpy?

A

Float data type

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

Does slicing creates a new array?

A

No, it does not. It only creates a view

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

Explain the array slicing with indexing

A

Indexing can be done with an array of integers,

a[[2, 3, 2, 4, 2]] # note: [2, 3, 2, 4, 2] is a Python list

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

How to create a sparse matrix in CSR format?

A

sparse_matrix = sparse.csr_matrix(array)

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

Name the difference between pandas and numpy

A

In contrast to NumPy, which requires that all entries in an
array be of the same type, pandas allows each column to have a separate type (for example, integers, dates, floating-point numbers, and strings)

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

Explain what is samples,features and shape

A

We see that the array contains measurements for 150 different flowers. Remember
that the individual items are called samples in machine learning, and their properties
are called features. The shape of the data array is the number of samples multiplied by
the number of features

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

What is a scatter?

A

A scatter plot of the data puts one feature along the x-axis and another
along the y-axis, and draws a dot for each data point

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

Theoretical question:how nearest number algorithm works?

A

It assigns a new label to a new point given depending to its nearest before-known neighbour.

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

How machine learning models are implemented in scikit-learn?

A

They are implemented at their own classes which are celled estimators.

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

Import in scikit-learn the k nearest neighbour?

A

from scilearn.neighbors import KNeighborsClassifier

knn = KNeighborsClassifier(n_neighbors=1)

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

For k nearest neighbours in scilearn , how you build the model on the training set?

A

knn.fit(X_trained,Y_trained)

17
Q

Name the major categories of supervised learning

A

Classification and regression
In classification, the goal is to predict a class label, which is a choice from a predefined
list of possibilities.
For regression tasks, the goal is to predict a continuous number, or a floating-point
number in programming terms (or real number in mathematical terms).

18
Q

What does it actually mean for the model to generalize from the training set to the test set?

A

If a model is able to make accurate predictions on unseen data

19
Q

What is bunch objects in skilearn?

A

Bunch objects, which contain some information about the dataset
as well as the actual data. All you need to know about Bunch objects
is that they behave like dictionaries, with the added benefit that you
can access values using a dot (as in bunch.key instead of
bunch[‘key’]).

20
Q

How to count the occurrences for each element of a numpy array?

A

Use the following np.bincount(np.array)

21
Q

In a dataset, what is the interactions?

A

It is all the relationships between the features of a dataset.