Basic Questions Flashcards

(34 cards)

1
Q

Name a function which is most useful to convert a multidimensional array into a one-dimensional array.

A

The flatten( ) can be used to convert a multidimensional array into a 1D array. If we modify the output array returned by flatten( ), it will not affect the original array because this function returns a copy of the original array.

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

If there are two variables defined as ‘a = 3’ and ‘b = 4’, will id() function return the same values for a and b?

A

The id() function in python returns the identity of an object, which is actually the memory address. Since, this identity is unique and constant for every object, it will not return same values for a and b.

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

In python, if we create two variables ‘mean = 7’ and ‘Mean = 7’, will both of them be considered as equivalent?

A

Python is a case-sensitive language. It has the ability to distinguish uppercase or lowercase letters and hence these variables ‘mean = 7’ and ‘Mean = 7’ will not be considered as equivalent.

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

What is the use of ‘inplace’ in pandas functions?

A

‘inplace’ is a parameter available for a number of pandas functions. It impacts how the function executes. Using ‘inplace = True’, the original dataframe can be modified and it will return nothing. The default behaviour is ‘inplace = False’ which returns a copy of the dataframe, without affecting the original dataframe.

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

How can you change the index of a dataframe in python?

A

DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False) keys: label or array-like or list of labels/arrays. This parameter can be either a single column key, a single array of the same length as the calling DataFrame, or a list containing an arbitrary combination of column keys and arrays.

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

How would check a number is prime or not using Python?

A

taking input from user number = int(input(“Enter any number: “)) # prime number is always greater than 1 if number > 1: for i in range(2, number): if (number % i) == 0: print(number, “is not a prime number”) break else: print(number, “is a prime number”) # if the entered number is less than or equal to 1 # then it is not a prime number else: print(number, “is not a prime number”)

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

What is the difference between univariate and bivariate analysis? What all different functions can be used in python?

A

Univariate analysis summarizes only one variable at a time while Bivariate analysis compares two variables. Below are a few functions which can be used in the univariate and bivariate analysis: 1. To find the population proportions with different types of blood disorders. df.Thal.value_counts() 2. To make a plot of the distribution : sns.distplot(df.Variable.dropna()) 3. Find the minimum, maximum, average, and standard deviation of data. There is a function called describe() which returns the minimum, maximum, mean etc. of the numerical variables of the data frame. 4. Find the mean of the Variable df.Variable.dropna().mean() 5. Boxplot to observe outliers sns.boxplot(x = ‘ ‘, y = ‘ ‘, hue = ‘ ‘, data=df) 6. Correlation plot: data.corr()

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

What is the difference between ‘for’ loop and ‘while’ loop?

A

‘for’ loop is used to obtain a certain result. In a for loop, the number of iterations to be performed is already known. In ‘while’ loop, the number of iterations is not known. Here, the statement runs until a specific condition is met and the assertion is proven untrue.

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

How will you import multiple excel sheets in a data frame?

A

The excel sheets can be read using ‘pd.read_excel()’ function into a dataframe and then using ‘pd.concat()’, concatenate all the excel sheets- Syntax: df = pd.concat(pd.read_excel(‘sheet_name’, sheet_name=None), ignore_index=True)

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

What is the difference between ‘Append’ and ‘Extend’ function?

A

The append() method adds an item to the end of the list. The syntax of the append() method is: list.append(item) On the other hand, the extend method extends the list by adding each element from iterable. The syntax of the extend() method is: list.extend(item)

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

What are the data types available in Python?

A

Python has the following standard data types: - Boolean - Set - Mapping Type: dictionary - Sequence Type: list, tuple, string - Numeric Type: complex, float, int.

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

Can you write a function using python to impute outliers?

A

import numpy as np def remove Outliers(x, outlierConstant): a = np.array(x) upper_quartile = np.percentile(a, 75) lower_quartile = np.percentile(a, 25) IQR = (upper_quartile - lower_quartile) * outlierConstant quartileSet = (lower_quartile - IQR, upper_quartile + IQR) resultList = for y in a.tolist(): if y > = quartileSet[0] and y < = quartileSet[1]: resultList.append(y) return resultList

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

Can any type of string be converted into an int, in Python?

A

Python offers the int() method that takes a String object as an argument and returns an integer. This can be done only when the value is either of numeric object or floating-point. But keep these special cases in mind - A floating-point (an integer with a fractional part) as an argument will return the float rounded down to the nearest whole integer.

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

How would check a number is armstrong number using Python?

A

Python program to check if the number is an Armstrong number or not # take input from the user num = int(input(“Enter a number: “)) # initialize sum sum = 0 # find the sum of the cube of each digit temp = num while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 # display the result if num == sum: print(num,”is an Armstrong number”) else: print(num,”is not an Armstrong number”)

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

What is the difference between list, array and tuple in Python?

A

The list is an ordered collection of data types. The list is mutable. Lists are dynamic and can contain objects of different data types. List elements can be accessed by index number. An array is an ordered collection of similar data types. An array is mutable. An array can be accessed by using its index number. Tuples are immutable and can store any type of data type. It is defined using (). It cannot be changed or replaced as it is an immutable data type.

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

What is the difference between iloc and loc activity?

A

loc gets rows (or columns) with particular labels from the index. iloc gets rows (or columns) at particular positions in the index and it only takes integers.

17
Q

How does the reverse function work in Python?

A

The built-in reverse( ) function reverses the contents of a list object inplace. That means, it does not return a new instance of the original list, rather it makes a direct change to the original list object. Syntax: list.reverse()

18
Q

What is the apply function in Python? How does it work?

A

Pandas.apply allow the users to pass a function and apply it on every single value of the Pandas series. Syntax: s.apply(func, convert_dtype=True, args=())

19
Q

How do you get the frequency of a categorical column of a dataframe using python?

A

Using df.value_counts(), where df is the dataframe. The value_counts( ) function returns the counts of the distinct elements in a dataframe column, sorted in descending order by default.

20
Q

Will range(5) include ‘5’ in its output?

A

The range() function in python always excludes the last integer from the result. Here it will generate a numeric series from ‘0’ to (5-1)=4, and it will not include ‘5’.

21
Q

How can you drop a column in python?

A

Pandas ‘drop()’ method is used to remove specific rows and columns. To drop a column, the parameter ‘axis’ should be set as ‘axis = 1’. This parameter determines whether to drop labels from the columns or rows (index). Default behaviour is, axis = 0. Syntax: df.drop(‘column_name’, axis=1)

22
Q

How NaN values behave while comparing with itself?

A

NaN values can not be compared with itself. That’s why, checking if a variable is equal to itself is the most popular way to look for NaN values. If it isn’t, it’s most likely a NaN value.

23
Q

How can we convert a python series object into a dataframe?

A

The to_frame() is a function that helps us to convert a series object into a dataframe. Syntax: Series.to_frame(name=None) name: this name will substitute the existing series name while creating the dataframe.

24
Q

What is supervised learning?

A

Supervised learning is a type of machine learning method in which algorithms are trained using well labeled training data, with independent variables tagged against a defined target variable. This technique allows for predictions and comparisons against the ground truth.

Example: Determining if a client might default on a loan or not.

25
What is unsupervised learning?
Unsupervised learning is a type of machine learning method in which models are trained using an unlabeled dataset, meaning there is no defined target variable. This method typically involves clustering the dataset into groups based on similarities. ## Footnote Example: Advertising companies segmenting the population into smaller groups with similar demographics.
26
What is an activation function, and why does a neural network need one?
Activation functions are mathematical functions that apply a transformation on the output of a layer in a neural network, introducing non-linearity. They are crucial for finding patterns and drawing decision boundaries in complex problems. ## Footnote Examples: Sigmoid function, Tanh function, ReLU function.
27
Why is the Sigmoid activation function not preferred in hidden layers of deep neural networks?
The Sigmoid function can lead to the vanishing gradient problem, where gradients become very small, slowing down learning. This makes it unsuitable for hidden layers in deep neural networks.
28
Why is it not a good idea to use the Sigmoid function in the output layer of a neural network meant for multi-class classification problems?
The Sigmoid function outputs probabilities without considering other options, which is not suitable for multi-class problems. The Softmax function is preferred as it ensures probabilities sum to 1.
29
What are the potential pitfalls of using neural networks for supervised learning?
Neural networks are computationally intensive and may require large datasets to outperform traditional models. Their black-box nature also limits interpretability, making them unsuitable for sensitive applications.
30
What hyperparameters can you tune inside neural networks?
Hyperparameters include the architecture (number of neurons, layers, activation functions), learning rate, number of epochs, batch size, and other nuanced parameters like momentum and dropout ratio.
31
What is the role of the Convolution operation in helping a neural network understand images?
Convolution extracts features from an input image by retaining pixel relationships and detecting patterns using filters. It replaces image pixels with new values based on the dot product of the filter and pixel vectors.
32
Why is text pre-processing an essential part of NLP? What happens if we fail to pre-process text data?
Text preprocessing removes noise from data, improving analysis accuracy. Failure to preprocess can lead to errors or suboptimal model performance.
33
What is the difference between stemming and lemmatization? Could you provide an example?
Stemming reduces words to their base form, which may not be a real word, while lemmatization results in actual words. ## Footnote Example: 'beautiful' and 'beautifully' are stemmed to 'beauti' but lemmatized to 'beautiful' and 'beautifully'.
34
Would you consider Logistic Regression to be a special case of using Neural Networks? If so, how?
Yes, logistic regression is a specialized case of a one-node neural network using the Sigmoid activation function and minimizing the Binary Cross-Entropy cost function.