Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load training data from a CSV file using pandas.
Intro to Computing
import pandas as pd train_data = pd.read_csv([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the filename.
Using incorrect function names like pd.load or csv.read.
✗ Incorrect
The filename must be a string inside quotes when using pd.read_csv().
2fill in blank
mediumComplete the code to split data into features and labels.
Intro to Computing
X = data.drop(columns=[1]) y = data['label']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the column name.
Using a variable name instead of the string.
✗ Incorrect
The column name must be a string inside quotes when dropping it.
3fill in blank
hardFix the error in the code to train a model using scikit-learn.
Intro to Computing
from sklearn.linear_model import LogisticRegression model = LogisticRegression() model.[1](X, y)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using train() instead of fit().
Using predict() before training the model.
✗ Incorrect
The method to train a model in scikit-learn is fit().
4fill in blank
hardFill both blanks to create a dictionary of feature means for training data where values are greater than 0.
Intro to Computing
feature_means = {col: data[col].[1]() for col in data.columns if (data[col][2] 0).any()} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using max() instead of mean().
Using < instead of > in the condition.
✗ Incorrect
We calculate the mean of each column and filter columns where values are greater than 0.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps feature names to their max values if max is greater than 10.
Intro to Computing
max_values = { [1] : data[[2]].[3]() for [2] in data.columns if data[[2]].max() > 10 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of max().
Using an undefined variable like 'feature' for the key.
✗ Incorrect
We use 'col' as key, iterate with 'col', and use max() to get max values.