0
0
ML Pythonml~10 mins

ML project structure in ML Python - Interactive Code Practice

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

Complete the code to create a folder for storing raw data in an ML project.

ML Python
import os
os.makedirs('data/[1]', exist_ok=True)
Drag options to blanks, or click blank then click option'
Araw
Bmodels
Cscripts
Dresults
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'models' or 'scripts' folders instead of 'raw' for data storage.
2fill in blank
medium

Complete the code to load a dataset CSV file from the data folder.

ML Python
import pandas as pd
df = pd.read_csv('data/[1]/dataset.csv')
Drag options to blanks, or click blank then click option'
Amodels
Braw
Cnotebooks
Dscripts
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'models' or 'scripts' folder which do not contain raw data.
3fill in blank
hard

Fix the error in the code to save a trained model to the models folder.

ML Python
import joblib
joblib.dump(model, 'models/[1].pkl')
Drag options to blanks, or click blank then click option'
Ascript
Bdataset
Ctrained_model
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Saving the model with wrong or confusing file names.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps filenames to their sizes in the data/raw folder.

ML Python
import os
file_sizes = {f: os.path.getsize(os.path.join('data/raw', [1])) for [2] in os.listdir('data/raw')}
Drag options to blanks, or click blank then click option'
Af
Bfilename
C'filename'
Dfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of variable names in path join.
5fill in blank
hard

Fill all three blanks to create a function that loads data, trains a model, and saves it.

ML Python
def train_and_save(data_path, model_path):
    import pandas as pd
    from sklearn.linear_model import LogisticRegression
    df = pd.read_csv(data_path)
    X = df.drop('[1]', axis=1)
    y = df['[2]']
    model = LogisticRegression()
    model.fit(X, y)
    import joblib
    joblib.dump(model, model_path + '/[3].pkl')
Drag options to blanks, or click blank then click option'
Atarget
Blabel
Ctrained_model
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names or file names that don't match conventions.