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)
For k nearest neighbours in scilearn , how you build the model on the training set?
knn.fit(X_trained,Y_trained)
Name the major categories of supervised learning
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).
What does it actually mean for the model to generalize from the training set to the test set?
If a model is able to make accurate predictions on unseen data
What is bunch objects in skilearn?
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’]).
How to count the occurrences for each element of a numpy array?
Use the following np.bincount(np.array)
In a dataset, what is the interactions?
It is all the relationships between the features of a dataset.