Python and ML MCQ
Python and ML MCQ
Answer: (b) C
Explanation: Python is written in C programming language, and it is also called CPython.
Q. Which one of the following is the correct extension of the Python file?
a. .py
b. .python
c. .p
d. None of these
Answer: (c) #
Explanation: "#" character is used in Python to make a single-line comment.
Q. Which of the following statements is correct regarding the object-oriented programming concept in
Python?
a. Classes are real-world entities while objects are not real
b. Objects are real-world entities while classes are not real
c. Both objects and classes are real-world entities
d. All of the above
Answer: (b) Objects are real-world entities while classes are not real
Explanation: None
Q. Why does the name of local variables start with an underscore discouraged?
a. To identify the variable
b. It confuses the interpreter
c. It indicates a private variable of a class
d. None of these
Q. Which of the following statements is correct for variable names in Python language?
a. All variable names must begin with an underscore.
b. Unlimited length
c. The variable name length is a maximum of 2.
d. All of the above
Q. Which one of the following has the highest precedence in the expression?
a. Division
b. Subtraction
c. Power
d. Parentheses
Answer: (d) 5
Explanation: The round function is a built-in function in the Python language that round-off the
value (like 3.85 is 4), so the output of this function will be 5.
Q. Which one of the following syntaxes is the correct syntax to read from a simple text file stored in
''d:\java.txt''?
a. Infile = open(''d:\\java.txt'', ''r'')
b. Infile = open(file=''d:\\\java.txt'', ''r'')
c. Infile = open(''d:\java.txt'',''r'')
d. Infile = open.file(''d:\\java.txt'',''r'')
Answer: (a) t
Explanation: The correct output of this program is "t" because -1 corresponds to the last index.
Answer: (a) 33
Explanation: A, B and C are hexadecimal integers with values 10, 11 and 12 respectively, so the sum
of A, B and C is 33.
Answer: (b) 1 2 3 4 5 6
Explanation: None
Answer: (c) 0 1 2
Explanation: None
Answer: (c) 0 1 2 0
Explanation: None
Answer: (b) 0 1 2
Explanation: None
Q. Study the following program:
1. d = {0, 1, 2}
2. for x in d:
3. print(x)
What will be the output of this statement?
a. {0, 1, 2} {0, 1, 2} {0, 1, 2}
b. 0 1 2
c. Syntax_Error
d. None of these above
Answer: (b) 0 1 2
Explanation: None
Q. Which of the following option is not a core data type in the python language?
a. Dictionary
b. Lists
c. Class
d. All of the above
Q. What error will occur when you execute the following code?
MANGO = APPLE
a. NameError
b. SyntaxError
c. TypeError
d. ValueError
NUMPY :
Question:
Correct syntax of the reshape() function in Numpy array python is -
1.array.reshape(shape)
2.reshape(shape,array)
3.reshape(array,shape)
4.reshape(shape)
Answer:3
Question:
How we can change the shape of the Numpy array in python?
1.By Shape()
2.By reshape()
3.By ord()
4.By change()
Answer:2
Question:
How we can convert the Numpy array to the list in python?
1.list(array)
2.list.array
3.array.list
4.None of the above
Answer:1
Question:
How we can find the type of numpy array in python ?
1.dtype
2.type
3.typei
4.itype
Answer:1
Question:
How we install Numpy in the system ?
1.install numpy
2.pip install python numpy
3.pip install numpy
4.pip install numpy python
Answer:3
Question:
It is possible to convert the Numpy array to list in python ?
1.Yes
2.No
3.Sometimes
4.None of the above
Answer:1
Question:
Minimum number of argument to pass in full() function in Numpy array ?
1.0
2.1
3.2
4.3
Answer:3
Question:
Numpy in the Python provides the
1.Function
2.Lambda function
3.Type casting
4.Array
Answer:4
Question:
Numpy.array(list), what it does ?
Question:
Shape() function in Numpy array is used to
Question:
What is the use of the size attribute in Numpy array in python ?
Question:
what is the use of the zeros() function in Numpy array in python ?
Question:
Which of the following argument we need to pass in reshape() function?
1.Array
2.Shape
3.only array
4.Both array and shape
Answer:4
Question:
Which of the following counts the number of elements in Numpy array ?
1.count()
2.return()
3.shape()
4.size()
Answer:4
Question:
Which of the following find the maximum number in the Numpy array ?
1.max(array)
2.array.max()
3.array(max)
4.None of the above
Answer:2
Question:
Which of the following is correct way to import the Numpy module in your program ?
1.import numpy
2.import numpy as np
3.from numpy import *
4.All of the above
Answer:4
Question:
Which of the following is not valid to import the numpy module ?
1.import numpy as np
2.import numpy as n
3.import numpy as p
4.None of the above
Answer:4
Question:
Which of the following is the essential argument to pass in full() function of Numpy array ?
1.shape
2.value
3.Both of the above
4.None of the above
Answer:3
Question:
Which of the following is used to convert the list data type to the Numpy array ?
1.array(list)
2.array.list
3.Numpy.array(list)
4.None of the above
Answer:3
Question:
Which of the following keyword is used to access the numpy module in python ?
1.access
2.import
3.fetch
4.from
Answer:2
import pandas as pd
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
print s['a']
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : A
Explanation: A pandas Series can be created using the following constructor : pandas.Series( data,
index, dtype, copy)
Q. What will be syntax for pandas dataframe?
A. minor_axis
B. major_axis
C. items
D. None of the above
View Answer
Ans : B
A. a python dict
B. an ndarray
C. a scalar value
D. All of the above
View Answer
Ans : D
Q. The ________ project builds on top of pandas and matplotlib to provide easy plotting of data.
A. yhat
B. Seaborn
C. Vincent
D. Pychart
View Answer
Ans : B
Explanation: ndim : Returns the number of dimensions of the underlying data, by definition 1
import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(2))
print s.size
A. 0
B. 1
C. 2
D. 3
View Answer
Ans : C
A. The integer format tracks only the locations and sizes of blocks of data.
B. Pandas follow the NumPy convention of raising an error when you try to convert something to a
bool.
C. Two kinds of SparseIndex are implemented
D. The integer format keeps an arrays of all of the locations where the data are not equal to the fill
value
View Answer
Ans : A
Explanation: The block format tracks only the locations and sizes of blocks of data.
A. science library
B. source library
C. significant library
D. scientific library
Ans : D
Explanation: SciPy, a scientific library for Python is an open source, BSD-licensed library for
mathematics, science and engineering.
A. scipy.cluster
B. scipy.source
C. scipy.interpolate
D. scipy.signal
Ans : B
A. By default, all the NumPy functions have been available through the SciPy namespace
B. There is no need to import the NumPy functions explicitly, when SciPy is imported.
C. SciPy is built on top of NumPy arrays
D. All of the above
Ans : D
import numpy as np
print np.linspace(1., 4., 6)
A. array([ 1. , 2.2, 2.8, 3.4, 4. ])
B. array([ 1. , 1.6, 2.8, 3.4, 4. ])
C. array([ 1. , 1.6, 2.2, 2.8, 3.4, 4. ])
D. array([ 1. , 1.6, 2.2, 2.8, 4. ])
Ans : C
Explanation: The above program will generate the following output : array([ 1. , 1.6, 2.2, 2.8, 3.4, 4. ])
A. import scipy.constants
B. from scipy.constants
C. import scipy.constants.package
D. from scipy.constants.package
Ans : B
A. G
B. e
C. R
D. k
Ans : D
Explanation: The above program will generate the following output : array([ 2., -2., 9.])
A. determinant()
B. SciPy.determinant()
C. det()
D. SciPy.det()
Ans : C
A. scipy.linalg also has some other advanced functions that are not in numpy.linalg
B. SciPy version might be faster depending on how NumPy was installed.
C. Both A and B
D. None of the above
Ans : D
Q. What relation is consider between Eigen value (lambda), square matrix (A) and Eign vector(v)?
A. Av = lambda*v
B. Av =Constant * lambda*v
C. Av =10 * lambda*v
D. Av != lambda*v
Ans : A
Explanation: We can find the Eigen values (lambda) and the corresponding Eigen vectors (v) of a
square matrix (A) by considering the following relation.
Q. p → 0q is not a?
A. hack clause
B. horn clause
C. structural clause
D. system clause
Ans : B
A. STACK(A,B)
B. LIST(A,B)
C. QUEUE(A,B)
D. ARRAY(A,B)
Ans : A
Explanation: The action 'STACK(A,B)' of a robot arm specify to Place block A on block B.
A. bottow-up parser
B. top parser
C. top-down parser
D. bottom parser
Ans : C
Explanation: A top-down parser begins by hypothesizing a sentence (the symbol S) and successively
predicting lower level constituents until individual preterminal symbols are written.
Q. A model of language consists of the categories which does not include ________.
A. System Unit
B. structural units.
C. data units
D. empirical units
Ans : B
Explanation: A model of language consists of the categories which does not include structural units.
A. Introduction
B. Analogy
C. Deduction
D. Memorization
Ans : A
Q. The model will be trained with data in one single batch is known as ?
A. Batch learning
B. Offline learning
C. Both A and B
D. None of the above
Ans : C
Explanation: we have end-to-end Machine Learning systems in which we need to train the model in
one go by using whole available training data. Such kind of learning method or algorithm is called
Batch or Offline learning.
Explanation: The following are various ML methods based on some broad categories : Based on
human supervision, Unsupervised Learning, Semi-supervised Learning and Reinforcement Learning
Q. In Model based learning methods, an iterative process takes place on the ML models that are built
based on various model parameters, called ?
A. mini-batches
B. optimizedparameters
C. hyperparameters
D. superparameters
Ans : C
Explanation: In Model based learning methods, an iterative process takes place on the ML models that
are built based on various model parameters, called hyperparameters.
Q. Which of the following is a widely used and effective machine learning algorithm based on the
idea of bagging?
A. Decision Tree
B. Regression
C. Classification
D. Random Forest
Ans : D
Explanation: The Radom Forest algorithm builds an ensemble of Decision Trees, mostly trained with
the bagging method.
Q. To find the minimum or the maximum of a function, we set the gradient to zero because:
Explanation: The gradient of a multivariable function at a maximum point will be the zero vector of
the function, which is the single greatest value that the function can achieve.
A. Factor analysis
B. Decision trees are robust to outliers
C. Decision trees are prone to be overfit
D. None of the above
Ans : C
Explanation: Allowing a decision tree to split to a granular degree makes decision trees prone to
learning every point extremely well to the point of perfect classification that is overfitting.
Explanation: All of the above techniques are different ways of imputing the missing values.
Q. When performing regression or classification, which of the following is the correct way to
preprocess the data?
Explanation: You need to always normalize the data first. If not, PCA or other techniques that are
used to reduce dimensions will give different results.
A. Using too large a value of lambda can cause your hypothesis to underfit the data.
B. Using too large a value of lambda can cause your hypothesis to overfit the data
C. Using a very large value of lambda cannot hurt the performance of your hypothesis.
D. None of the above
Ans : D
Explanation: A large value results in a large regularization penalty and therefore, a strong preference
for simpler models, which can underfit the data.
Q. Which of the following techniques can not be used for normalization in text mining?
A. Stemming
B. Lemmatization
C. Stop Word Removal
D. None of the above
Ans : C
Q. In which of the following cases will K-means clustering fail to give good results?
1) Data points with outliers
2) Data points with different densities
3) Data points with nonconvex shapes
A. 1 and 2
B. 2 and 3
C. 1 and 3
D. All of the above
Ans : D
Explanation: K-means clustering algorithm fails to give good results when the data contains outliers,
the density spread of data points across the data space is different, and the data points follow
nonconvex shapes.
Q. Which of the following is a reasonable way to select the number of principal components "k"?
A. Choose k to be the smallest value so that at least 99% of the varinace is retained.
B. Choose k to be 99% of m (k = 0.99*m, rounded to the nearest integer).
C. Choose k to be the largest value so that 99% of the variance is retained.
D. Use the elbow method.
Ans : A
Explanation: This will maintain the structure of the data and also reduce its dimension.
Explanation: Sentence parsers analyze a sentence and automatically build a syntax tree.