0
0
Intro to Computingfundamentals~10 mins

Training data and models in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A'train.csv'
Btrain.csv
Ccsv.read('train.csv')
Dpd.load('train.csv')
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the filename.
Using incorrect function names like pd.load or csv.read.
2fill in blank
medium

Complete 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'
A'label'
Blabel
C['label']
Dlabel_column
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the column name.
Using a variable name instead of the string.
3fill in blank
hard

Fix 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'
Apredict
Btrain
Ctransform
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using train() instead of fit().
Using predict() before training the model.
4fill in blank
hard

Fill 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'
Amean
Bmax
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using max() instead of mean().
Using < instead of > in the condition.
5fill in blank
hard

Fill 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'
Afeature
Bcol
Cmax
Dmean
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of max().
Using an undefined variable like 'feature' for the key.