Numpy Flashcards
Define an array at numpy
import numpy as np
a=np.array([0,1,2,4])
Create a multidimensional array in numpy
b = np.array([[0, 1, 2], [3, 4, 5]]) # 2 x 3 array
How to create a numpy array in one move?
np.arange(10)
How to create an array with defined number of points between a range of numbers?
c = np.linspace(0, 1, 6)
Create
a) An array of ones
b) An array of zeros
c) A diagonal array
a = np.ones((3, 3)) # reminder: (3, 3) is a tuple b = np.zeros((2, 2) c = np.eye(3
Which is the most common data type in numpy?
Float data type
Does slicing creates a new array?
No, it does not. It only creates a view
Explain the array slicing with indexing
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 to create a sparse matrix in CSR format?
sparse_matrix = sparse.csr_matrix(array)
Name the difference between pandas and numpy
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)
Explain what is samples,features and shape
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
What is a scatter?
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
Theoretical question:how nearest number algorithm works?
It assigns a new label to a new point given depending to its nearest before-known neighbour.
How machine learning models are implemented in scikit-learn?
They are implemented at their own classes which are celled estimators.
Import in scikit-learn the k nearest neighbour?
from scilearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=1)