WorksheetsMastering Python and Machine Learning
Total questions: 20
Worksheet time: 10mins
What is the syntax to create a list in Python?
list_name =
list_name : {item1, item2, item3}
list_name = [item1, item2, item3]
list_name = (item1, item2, item3)
How do you append an item to a list in Python?
Use the append() method, e.g., my_list.append(item).
Insert the item using my_list.insert(item).
Use the add() method, e.g., my_list.add(item).
Combine lists with my_list += [item].
What is the difference between a list and a tuple in Python?
Tuples are mutable; lists are immutable.
Lists are mutable; tuples are immutable.
Lists are faster than tuples in all cases.
Lists can contain only numbers; tuples can contain any data type.
How can you convert a list to a tuple in Python?
list(my_list)
array(my_list)
tuple(my_list)
convert(my_list)
What function is used to create a NumPy array from a list?
numpy.array()
numpy.list()
numpy.create_array()
array.numpy()
How do you access the shape of a NumPy array?
array.size
array.dimensions
array.shape
array.length
What method would you use to find the mean of a NumPy array?
numpy.mean()
numpy.median()
numpy.sum()
numpy.average()
How can you reshape a NumPy array?
Use array.change_shape(new_shape) to modify the shape of a NumPy array.
Use array.reshape(new_shape) to reshape a NumPy array.
Call reshape_array(array, new_shape) to reshape a NumPy array.
Use array.resize(new_shape) to change the size of a NumPy array.
What is a DataFrame in Pandas?
A DataFrame is a type of database in Pandas.
A DataFrame is a two-dimensional labeled data structure in Pandas.
A DataFrame is a one-dimensional array in Pandas.
A DataFrame is a graphical representation of data in Pandas.
How do you read a CSV file into a Pandas DataFrame?
Use `pd.read_csv('file_path.csv')` to read a CSV file into a DataFrame.
Use `pd.load_csv('file_path.csv')` to read a CSV file into a DataFrame.
Read the CSV file with `pd.import_csv('file_path.csv')` into a DataFrame.
You can load a CSV file using `pd.open_csv('file_path.csv')` to create a DataFrame.
What method is used to display the first few rows of a DataFrame?
top()
slice()
head()
firstRows()
How can you filter rows in a Pandas DataFrame?
Apply the `map()` method
Use the `filter()` function
Sort the DataFrame by index
Use boolean indexing or the `query()` method.
What is the purpose of Matplotlib in Python?
To manage databases in Python.
To perform web scraping tasks.
To write and execute Python scripts.
The purpose of Matplotlib in Python is to create visualizations and plots of data.
How do you create a simple line plot using Matplotlib?
import matplotlib.pyplot as plt; plt.draw(x, y); plt.render()
import matplotlib as mpl; mpl.plot(x, y); mpl.show()
import matplotlib.pyplot as plt; plt.line(x, y); plt.display()
import matplotlib.pyplot as plt; x = [1, 2, 3, 4]; y = [10, 20, 25, 30]; plt.plot(x, y); plt.show()
What is the difference between classification and regression in machine learning?
Classification requires more data than regression.
Classification is used for time series; regression is for image data.
Classification predicts numerical values; regression predicts categories.
Classification predicts categories; regression predicts continuous values.
Name a common classification algorithm used in machine learning.
Linear Regression
K-Means Clustering
Decision Tree
Support Vector Machine
What is the purpose of the training set in machine learning?
The purpose of the training set in machine learning is to train the model.
To store the final model parameters
To provide real-time predictions
To validate the model's performance
What are the steps in the machine learning cycle?
Identify stakeholders, Develop software, Conduct training
Define the problem, Collect data, Prepare data, Choose a model, Train the model, Evaluate the model, Tune the model, Deploy the model, Monitor and maintain the model.
Select features, Validate data, Present findings
Analyze results, Collect feedback, Implement changes
How do you evaluate the performance of a regression model?
Use metrics like MAE, MSE, RMSE, and R-squared to evaluate performance.
Evaluate based on the number of features used in the model.
Use only visual inspection of the model's predictions.
Check the training time of the model as the main metric.
What is overfitting in the context of machine learning?
Overfitting is when a model is trained on too little data, leading to poor performance.
Overfitting is when a model performs well on unseen data but poorly on training data.
Overfitting is when a model performs well on training data but poorly on unseen data due to excessive complexity.
Overfitting occurs when a model is too simple and cannot capture the underlying patterns in the data.
