Professional Documents
Culture Documents
Data Science
Data Science
def foo(x=[]):
x.append(1)
return x
print(foo())
print(foo())
a) [1], [1, 1]
b) [1], [1]
d) [1], [1, 1]
x = [1, 2, 3]
y=x
x += [4, 5]
print(y)
a) [1, 2, 3, 4, 5]
b) [1, 2, 3]
d) Error
Answer: a) [1, 2, 3, 4, 5]
3.Which of the following is true about Python's Global Interpreter Lock (GIL)?
Answer: a) It ensures that only one thread executes Python bytecode at a time.
[x for x in range(5) if x % 2 == 0]
a) [0, 2, 4]
b) [1, 3, 5]
c) [0, 1, 2, 3, 4]
d) [0, 1, 2, 3, 4, 5]
Answer: a) [0, 2, 4]
5.What is the output of the following code snippet?
print((lambda x: x * 2)(5))
a) 5
b) 10
c) 25
d) Error
Answer: b) 10
6.Which of the following is a valid way to open a file named "example.txt" in Python for reading?
def f():
try:
print("a")
return
except:
print("b")
finally:
print("c")
f()
a) a
b) a c
c) a c b
d) a b c
Answer: b) a c
x = 10
def foo():
global x
x += 5
return x
print(foo())
a) 10
b) 15
c) 20
d) Error
Answer: c) 20
Answer: a) It creates a new list by applying a function to each element of an existing list.
14.Which of the following evaluation metrics is suitable for imbalanced classification problems?
a) Accuracy
b) Precision
c) Recall
d) F1-score
Answer: d) F1-score
17.What is the purpose of the kernel trick in Support Vector Machines (SVM)?
21.Which of the following statistical tests is used to determine if there is a significant association
between two categorical variables?
a) T-test
b) Chi-square test
c) ANOVA
d) Z-test
Answer: b) To determine the probability of observing the data if the null hypothesis is true
a) Mean
b) Median
c) Variance
d) Mode
Answer: c) Variance
24.In linear regression, what does the coefficient of determination (R-squared) measure?
a) The strength of the relationship between the independent and dependent variables
b) The accuracy of the regression model's predictions
c) The proportion of the total variation in the dependent variable explained by the independent variable
d) The significance of the regression coefficients
Answer: c) The proportion of the total variation in the dependent variable explained by the independent
variable
25.Which of the following probability distributions is used to model the time until an event occurs?
a) Normal distribution
b) Poisson distribution
c) Exponential distribution
d) Binomial distribution
a) Mean
b) Median
c) Variance
d) Mode
Answer: c) Variance
Answer: a) To ensure that the treatment and control groups are similar
29.What is the purpose of the F-test in ANOVA?
30.What is the main advantage of using a non-parametric test over a parametric test?
Answer: b) Non-parametric tests make fewer assumptions about the data distribution
Answer: a) plot()
a) Attaches a data frame to the search path for easier access to its columns
b) Attaches a library for use in the current session
c) Attaches a package for use in the current session
d) Attaches a function to an object
Answer: a) Attaches a data frame to the search path for easier access to its columns
34.Which of the following is a valid way to create a new variable total in a data frame df that sums the
values of variables var1 and var2?
a) cumsum()
b) sum()
c) cumulative()
d) cumulative_sum()
Answer: a) cumsum()
Answer: b) dplyr
39.What is the purpose of the lapply() function in R?
a) read.table()
b) read.csv()
c) read.csv2()
d) read.delim()
Answer: b) read.csv()
42.Which of the following methods is used to fill missing values in a pandas DataFrame with a
specified value?
a) fillna()
b) dropna()
c) replace()
d) interpolate()
Answer: a) fillna()
43.What does the pivot_table() function in pandas do?
44.Which of the following methods is used to concatenate two or more pandas DataFrames vertically?
a) merge()
b) concat()
c) join()
d) append()
Answer: d) append()
a) rename()
b) relabel()
c) columns()
d) set_columns()
Answer: a) rename()
48.Which of the following methods is used to create a new column in a pandas DataFrame based on
values in existing columns?
a) map()
b) apply()
c) transform()
d) assign()
Answer: d) assign()
50.Which of the following methods is used to pivot a pandas DataFrame from long to wide format?
a) pivot_table()
b) pivot()
c) melt()
d) wide()
Answer: b) pivot()
Answer: a) numpy.unique()
Answer: a) numpy.mean()
a) numpy.std()
b) numpy.var()
c) numpy.mean()
d) numpy.median()
Answer: a) numpy.std()
Answer: b) It is used to find the indices of elements in an array that satisfy a condition
60.Which numpy function is used to compute the cumulative sum of elements in an array?
a) numpy.cumsum()
b) numpy.sum_cumulative()
c) numpy.cumulative_sum()
d) numpy.sum() with the cumulative parameter set to True
Answer: a) numpy.cumsum()
64.Which of the following is NOT a valid way to set the title of a plot in matplotlib?
a) plt.title("Title")
b) plt.set_title("Title")
c) plt.suptitle("Title")
d) plt.figtext("Title")
Answer: b) plt.set_title("Title")
66.Which of the following methods is used to customize the color of a plot in matplotlib?
a) color()
b) set_color()
c) set_facecolor()
d) set_edgecolor()
Answer: a) color()
70.Which of the following methods is used to set the x-axis limits in matplotlib?
a) plt.xlim()
b) plt.set_xlim()
c) plt.set_xlimits()
d) plt.axis()
Answer: a) plt.xlim()
71.What is Django?
a) A programming language
b) A web framework for building web applications
c) A database management system
d) A server-side scripting language
a) Basic authentication
b) Token-based authentication
c) Session-based authentication
d) OAuth authentication
75.Which of the following is used to define the URL patterns in a Django application?
a) URLs.py
b) Views.py
c) Models.py
d) Settings.py
Answer: a) URLs.py
Answer: c) MongoDB
81.What is FastAPI?
Answer: b) A Python web framework for building APIs with a focus on speed
82.Which of the following Python web frameworks is FastAPI built on top of?
a) Flask
b) Django
c) Starlette
d) Falcon
Answer: c) Starlette
86.Which Python type hinting feature does FastAPI heavily rely on for automatic data validation and
serialization?
a) Annotations
b) Typing
c) Protocols
d) Generics
Answer: a) Annotations
88.Which of the following is a valid way to define a path parameter in a FastAPI route?
a) /items/{item_id}
b) /items/:item_id
c) /items/item_id
d) /items?item_id={item_id}
Answer: a) /items/{item_id}
a) JSON
b) HTML
c) XML
d) Plain text
Answer: c) XML
91.What is K-means clustering used for?
a) Dimensionality reduction
b) Classification
c) Regression
d) Clustering
Answer: d) Clustering
a) Entropy
b) Information gain
c) Inertia
d) Silhouette coefficient
Answer: c) Inertia
93.How does the K-means algorithm initialize cluster centroids?
a) Randomly
Answer: a) Randomly
95.Which of the following is a metric used to evaluate the quality of K-means clustering?
a) F1 score
d) R-squared
97.How does the K-means algorithm update cluster centroids in each iteration?
Answer: a) By computing the mean of all data points assigned to each cluster
c) It calculates the sum of squared distances from data points to their assigned centroids for different
values of K
Answer: c) It calculates the sum of squared distances from data points to their assigned centroids for
different values of K
101.What is scikit-learn?
a) sklearn.preprocessing
b) sklearn.feature_extraction
c) sklearn.model_selection
d) sklearn.neural_network
Answer: d) sklearn.neural_network
103.What is the purpose of the train_test_split function in scikit-learn?
a) K-means clustering
b) Decision trees
c) Linear regression
a) fit()
b) train()
c) predict()
d) transform()
Answer: a) fit()
107.Which metric is commonly used to evaluate the performance of classification models in scikit-
learn?
c) Accuracy
d) R-squared
Answer: c) Accuracy
108.What is the purpose of the StandardScaler class in scikit-learn?
b) K-means clustering
c) Random Forest
d) Linear Regression
a) Sequential model
d) Model Subclassing
116.Which loss function is commonly used for binary classification tasks in Keras?
b) Binary Cross-Entropy
c) Categorical Cross-Entropy
d) Kullback-Leibler Divergence
a) Dropout regularization
b) L1 regularization
c) L2 regularization
a) Dense layer
b) Convolutional layer
c) Pooling layer
d) Activation layer