0% found this document useful (0 votes)
11 views15 pages

Ai ML Unit 2

The document provides a comprehensive overview of key concepts and functions related to NumPy, Pandas, PCA, LDA, and Matplotlib in Python. It includes multiple-choice questions and answers that cover topics such as array creation, data manipulation, dimensionality reduction, and data visualization techniques. This serves as a study guide for understanding essential Python libraries used in data analysis and machine learning.

Uploaded by

rachitmadhal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views15 pages

Ai ML Unit 2

The document provides a comprehensive overview of key concepts and functions related to NumPy, Pandas, PCA, LDA, and Matplotlib in Python. It includes multiple-choice questions and answers that cover topics such as array creation, data manipulation, dimensionality reduction, and data visualization techniques. This serves as a study guide for understanding essential Python libraries used in data analysis and machine learning.

Uploaded by

rachitmadhal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

Introduction to NumPy & nD Arrays

1. What is NumPy mainly used for in Python?

o a) Efficient handling of large numerical data ✅

o b) Text processing

o c) Image editing

o d) Creating GUIs

2. Which function is used to create a NumPy array?

o a) np.array() ✅

o b) np.create()

o c) np.list()

o d) np.ndarray()

3. How do you create a 1D array with values from 0 to 9?

o a) np.arange(10) ✅

o b) np.range(10)

o c) np.linspace(0, 9)

o d) np.create(0,9)

4. What is the default data type in NumPy arrays?

o a) float64 ✅

o b) int32

o c) string

o d) object

5. What is the shape of the following array?

python

CopyEdit

arr = np.array([[1, 2, 3], [4, 5, 6]])

o a) (2,3) ✅
o b) (3,2)

o c) (6,)

o d) (1,6)

6. Which of the following is used to access the element at row index 1, column index 2 in a
2D array?

o a) arr[1,2] ✅

o b) arr[2,1]

o c) arr(1,2)

o d) arr[2][1]

7. How do you reshape a 1D NumPy array into a 3x3 matrix?

o a) arr.reshape(3,3) ✅

o b) arr.resize(3,3)

o c) arr.shape(3,3)

o d) arr.to(3,3)

8. What function is used to find the mean of all elements in a NumPy array?

o a) np.mean(arr) ✅

o b) np.avg(arr)

o c) arr.mean()

o d) arr.median()

9. Which operation performs element-wise multiplication between two NumPy arrays?

o a) arr1 * arr2 ✅

o b) np.dot(arr1, arr2)

o c) arr1 @ arr2

o d) arr1.add(arr2)

10. Which function is used to generate an identity matrix in NumPy?

 a) np.eye() ✅
 b) np.identity()

 c) np.matrix()

 d) np.ones()

2. Introduction to Pandas & DataFrames

11. What is Pandas used for in Python?

 a) Data manipulation and analysis ✅

 b) Machine learning

 c) Creating websites

 d) File compression

12. Which function is used to create a Pandas DataFrame?

 a) pd.DataFrame() ✅

 b) pd.create()

 c) pd.array()

 d) pd.list()

13. What method is used to read a CSV file into a Pandas DataFrame?

 a) pd.read_csv() ✅

 b) pd.load_csv()

 c) pd.import_csv()

 d) pd.file_csv()

14. How can you display the first five rows of a DataFrame?

 a) df.head() ✅

 b) df.top()

 c) df.first()

 d) df.start()

15. What function is used to get summary statistics of a DataFrame?


 a) df.describe() ✅

 b) df.summary()

 c) df.stats()

 d) df.info()

3. Dimensionality Reduction (PCA & LDA)

16. What does PCA stand for?

 a) Principal Component Analysis ✅

 b) Primary Component Algorithm

 c) Partial Correlation Analysis

 d) Principal Classification Approach

17. What is the main goal of PCA?

 a) Reduce dimensionality while preserving variance ✅

 b) Increase dataset size

 c) Remove missing values

 d) Cluster data

18. What is the key difference between PCA and LDA?

 a) PCA focuses on variance, LDA focuses on class separation ✅

 b) LDA is unsupervised, PCA is supervised

 c) PCA is used in deep learning, LDA is not

 d) PCA increases dimensions while LDA reduces

19. What is the first step in PCA?

 a) Standardizing the data ✅

 b) Computing eigenvalues

 c) Selecting principal components

 d) Visualizing data
20. Which library provides PCA implementation in Python?

 a) scikit-learn ✅

 b) NumPy

 c) Pandas

 d) TensorFlow

4. Data Visualization using Matplotlib

21. Which command is used to create a line plot in Matplotlib?

 a) plt.plot(x, y) ✅

 b) plt.line(x, y)

 c) plt.scatter(x, y)

 d) plt.show(x, y)

22. How do you display a plot?

 a) plt.show() ✅

 b) plt.display()

 c) plt.render()

 d) plt.view()

23. What function creates a bar graph?

 a) plt.bar() ✅

 b) plt.graph()

 c) plt.barchart()

 d) plt.plot()

24. What parameter controls line style in Matplotlib?

 a) linestyle ✅

 b) linestyle_width

 c) border
 d) style

25. Which function creates a histogram?

 a) plt.hist() ✅

 b) plt.barh()

 c) plt.scatter()

 d) plt.line()

26. What function is used to create subplots?

 a) plt.subplot() ✅

 b) plt.subplots()

 c) plt.figure()

 d) plt.plot()

27. How do you add a title to a Matplotlib plot?

 a) plt.title("My Plot") ✅

 b) plt.heading("My Plot")

 c) plt.name("My Plot")

 d) plt.show_title("My Plot")

28. What function adds x-axis labels to a plot?

 a) plt.xlabel() ✅

 b) plt.xlabels()

 c) plt.axis_label()

 d) plt.labelx()

29. How do you create a pie chart?

 a) plt.pie() ✅

 b) plt.chart()

 c) plt.bar()

 d) plt.piechart()
30. Which library is commonly used along with Matplotlib for visualization?

 a) Seaborn ✅

 b) TensorFlow

 c) OpenCV

31. NumPy: Advanced Operations

31. What function is used to compute the dot product of two NumPy arrays?

 a) np.dot(arr1, arr2) ✅

 b) arr1 * arr2

 c) np.multiply(arr1, arr2)

 d) np.cross(arr1, arr2)

32. How can you find the index of the maximum value in a NumPy array?

 a) np.argmax(arr) ✅

 b) np.max(arr)

 c) arr.index(max)

 d) np.argmax(arr, axis=1)

33. What is the function of np.linspace(0, 10, 5)?

 a) Creates an array of 5 evenly spaced values between 0 and 10 ✅

 b) Creates a list from 0 to 10

 c) Creates an empty array

 d) Generates random numbers

34. What is the function of np.random.rand(3,3)?

 a) Generates a 3×3 matrix with random values between 0 and 1 ✅

 b) Generates a matrix of ones

 c) Generates random integers

 d) Creates a DataFrame

35. What function is used to stack arrays vertically in NumPy?


 a) np.vstack() ✅

 b) np.hstack()

 c) np.stack()

 d) np.append()

32. Pandas: DataFrame Operations

36. Which function is used to check for missing values in a Pandas DataFrame?

 a) df.isnull() ✅

 b) df.null()

 c) df.check_missing()

 d) df.missing()

37. How can you drop rows with missing values from a Pandas DataFrame?

 a) df.dropna() ✅

 b) df.remove_missing()

 c) df.fillna()

 d) df.clean()

38. What function is used to group DataFrame rows based on a column?

 a) df.groupby("column_name") ✅

 b) df.merge("column_name")

 c) df.sort("column_name")

 d) df.select("column_name")

39. Which of the following functions is used to merge two DataFrames?

 a) pd.merge(df1, df2) ✅

 b) df1.join(df2)

 c) df1.append(df2)

 d) df1.concat(df2)
40. Which Pandas function is used to reset the index of a DataFrame?

 a) df.reset_index() ✅

 b) df.drop_index()

 c) df.reindex()

 d) df.modify_index()

33. PCA & LDA: Dimensionality Reduction

41. What mathematical concept is used in PCA?

 a) Eigenvectors & Eigenvalues ✅

 b) Gradient Descent

 c) Neural Networks

 d) Decision Trees

42. What is the main benefit of using PCA?

 a) Reduces computation cost and avoids overfitting ✅

 b) Increases dataset size

 c) Removes missing values

 d) Makes data nonlinear

43. What method is commonly used to decide how many principal components to keep in
PCA?

 a) Explained variance ratio ✅

 b) Mean squared error

 c) K-Means clustering

 d) Decision trees

44. LDA is mainly used for:

 a) Supervised dimensionality reduction ✅

 b) Unsupervised learning
 c) Neural networks

 d) Feature extraction

45. How does LDA differ from PCA?

 a) LDA maximizes class separability, PCA maximizes variance ✅

 b) PCA and LDA are the same

 c) PCA works only for text data

 d) LDA increases dimensionality

34. Matplotlib: Data Visualization

46. What argument is used to change the color of a Matplotlib plot?

 a) color ✅

 b) linewidth

 c) marker

 d) fontsize

47. What function is used to set axis labels in Matplotlib?

 a) plt.xlabel() and plt.ylabel() ✅

 b) plt.axis_labels()

 c) plt.labels()

 d) plt.set_axis()

48. What function is used to set the figure size in Matplotlib?

 a) plt.figure(figsize=(width, height)) ✅

 b) plt.size(width, height)

 c) plt.dimensions(width, height)

 d) plt.set_size()
49. What is the purpose of plt.legend() in Matplotlib?

 a) Displays labels for different plots in the figure ✅

 b) Sets x-axis labels

 c) Changes color of the plot

 d) Adds a title

50. What function is used to save a Matplotlib figure as an image?

 a) plt.savefig("filename.png") ✅

 b) plt.export("filename.png")

 c) plt.write("filename.png")

 d) plt.store("filename.png")

51. Which NumPy function is used to compute the cumulative sum of an array?

 a) np.cumsum() ✅

 b) np.sum()

 c) np.accumulate()

 d) np.cumprod()

52. What does np.unique(arr) return?

 a) An array of unique elements from arr ✅

 b) The maximum value in arr

 c) The sorted version of arr

 d) A random subset of arr

53. What does np.random.randint(1, 10, size=(3,3)) do?

 a) Generates a 3x3 array of random integers between 1 and 9 ✅

 b) Generates a 3x3 identity matrix

 c) Creates a DataFrame

 d) Returns an array of ones


54. What is the purpose of np.where() in NumPy?

 a) Finds indices where a condition is met ✅

 b) Finds the mean of an array

 c) Generates random numbers

 d) Removes missing values

55. What function is used to flatten a NumPy array?

 a) arr.flatten() ✅

 b) arr.reshape()

 c) arr.squeeze()

 d) arr.expanded()

36. Pandas: Data Manipulation

56. Which function is used to rename columns in a Pandas DataFrame?

 a) df.rename(columns={'old_name': 'new_name'}) ✅

 b) df.rename_columns({'old_name': 'new_name'})

 c) df.columns.rename({'old_name': 'new_name'})

 d) df.set_columns({'old_name': 'new_name'})

57. What function is used to filter rows based on a condition?

 a) df[df['column'] > value] ✅

 b) df.filter('column', value)

 c) df.select('column', value)

 d) df.rows('column', value)

58. Which Pandas function is used to fill missing values?

 a) df.fillna(value) ✅

 b) df.replace_null(value)

 c) df.fill_missing(value)
 d) df.complete_na(value)

59. How can you sort a Pandas DataFrame by a specific column?

 a) df.sort_values('column_name') ✅

 b) df.order_by('column_name')

 c) df.arrange('column_name')

 d) df.set_order('column_name')

60. What function is used to drop a column from a Pandas DataFrame?

 a) df.drop(columns=['column_name']) ✅

 b) df.remove_column('column_name')

 c) df.delete_column('column_name')

 d) df.pop('column_name')

37. PCA & LDA: Applications

61. PCA reduces dimensionality by:

 a) Finding new axes that maximize variance ✅

 b) Removing outliers

 c) Reducing data size

 d) Ignoring categorical features

62. LDA is mainly used in:

 a) Supervised classification tasks ✅

 b) Clustering

 c) Image processing

 d) Feature scaling

63. Which step is required before applying PCA?

 a) Standardizing the data ✅

 b) One-hot encoding
 c) Feature selection

 d) Data cleaning

64. In PCA, how are principal components ranked?

 a) By explained variance ✅

 b) By the number of missing values

 c) By their correlation

 d) By feature count

65. LDA works best when:

 a) There is a clear separation between classes ✅

 b) Data is completely unstructured

 c) Data is unlabeled

 d) There is only one class

38. Matplotlib: Advanced Plotting

66. How can you change the figure background color in Matplotlib?

 a) plt.figure(facecolor='color') ✅

 b) plt.background('color')

 c) plt.colorize('color')

 d) plt.theme('color')

67. What does plt.grid(True) do?

 a) Adds grid lines to the plot ✅

 b) Creates a bar graph

 c) Changes background color

 d) Rotates axis labels

68. What function is used to change the size of text labels in Matplotlib?

 a) fontsize parameter ✅
 b) textsize

 c) labelsize

 d) markersize

69. How can you save a Matplotlib figure with a transparent background?

 a) plt.savefig('figure.png', transparent=True) ✅

 b) plt.export('figure.png', background=None)

 c) plt.store('figure.png', clear_bg=True)

 d) plt.write('figure.png', bg=0)

70. What does plt.xlim(0, 10) do in Matplotlib?

 a) Sets the x-axis range from 0 to 10 ✅

 b) Adjusts y-axis limits

 c) Rotates the x-axis labels

 d) Changes the line width

You might also like