Note down your answer here.
# sample sizes: from 1000 to the full dataset (50 000)
input_sizes = [1000, 10000, 50000]
emissions_most_popular = []
emissions_top_ten = []

# footprint of get_most_popular_course on the different sample sizes
for input_size in input_sizes:
    tracker = OfflineEmissionsTracker(log_level="error", country_iso_code="IRL")
    tracker.start()
    try:
        get_most_popular_course(course_data.head(input_size))
    finally:
        emissions_most_popular.append(tracker.stop())


# footprint of get_top_ten_popular_courses on the different sample sizes
for input_size in input_sizes:
    tracker = OfflineEmissionsTracker(log_level="error", country_iso_code="IRL")
    tracker.start()
    try:
        get_top_ten_popular_courses(course_data.head(input_size))
    finally:
        emissions_top_ten.append(tracker.stop())

# bundling the results into a dataframe
emissions = pd.DataFrame({
        "Input size": input_sizes,
        "get_most_popular_course()": emissions_most_popular,
        "get_top_ten_popular_courses()": emissions_top_ten,
    }).set_index("Input size")

# Export to CSV
# emissions.to_csv("res/code_emissions.csv")

# and display the resulting dataframe
emissions
  
# loading the list of countries
import json
with open('res/global_energy_mix.json') as f:
    data = json.load(f)
countries = list(data.keys())

# empty dict for storing results
emissions_by_country = {}

# looping over countries to execute 'get_most_popular_course' on 100 samples and get the corresponding emissions
for country_iso_code in countries:
    tracker = OfflineEmissionsTracker(log_level="error", country_iso_code=country_iso_code)
    tracker.start()
    try:
        get_most_popular_course(course_data.head(100))
    finally:
         emissions_by_country[country_iso_code] = tracker.stop()

# bundling the results into a dataframe
emissions_by_country = pd.DataFrame(emissions_by_country.items(), columns=['Country', 'Emissions'])

# replacing the country codes by their names
country_iso_codes_to_names = pd.read_csv('res/countries.csv')
emissions_by_country['Country'] = country_iso_codes_to_names['Country name']
emissions_by_country.set_index('Country', inplace=True)

# Export to CSV
# emissions_by_country.to_csv("res/emissions_by_country.csv")

# Display
emissions_by_country
# Measuring the emissions of 'get_most_popular_course' on the whole dataset in Kenya
tracker = OfflineEmissionsTracker(log_level="error", country_iso_code="KEN")
tracker.start()
try:
    get_most_popular_course(course_data)
finally:
    emissions_per_call_KEN = tracker.stop()

print("Total emissions: ", emissions_per_call_KEN, "kg of CO₂-equivalents [CO₂eq]")
# List of the model types we want to compare
algorithm_list = ["Random forest", "K-nearest neighbors", "Logistic regression", "Multi-layer perceptron"]

# Create a table to store the results
train_algorithm_comparison = pd.DataFrame({'Training Emissions [kg of CO2 eq.]': pd.Series(dtype='float')}, 
                                          index = algorithm_list)

# Iterate over our model types
for algorithm in algorithm_list:
    # Initialize the tracker
    tracker = OfflineEmissionsTracker(log_level="error", country_iso_code="IRL")
    
    # Start the tracker
    tracker.start()
    
    try:
        # Train the ML model
        model = train_model(algorithm, train_features, train_label)
        
    finally:
        # Stop the tracker and get the emissions
        emissions = tracker.stop()

    # Save results
    train_algorithm_comparison.at[algorithm, 'Training Emissions [kg of CO2 eq.]'] = emissions

    # Save the trained model in a file
    with open('models/'+algorithm+'.pkl','wb') as f:
        pickle.dump(model, f, protocol=pickle.HIGHEST_PROTOCOL)

# Export emissions to CSV
# train_algorithm_comparison.to_csv("res/train_algorithm_comparison.csv")

# Display
display(train_algorithm_comparison)
# List of the model types we want to compare
algorithm_list = ["Random forest", "K-nearest neighbors", "Logistic regression", "Multi-layer perceptron"]

# Create a table to store the results
eval_algorithm_comparison = pd.DataFrame({'Evaluation Emissions [kg of CO2 eq.]': pd.Series(dtype='float'), 
                                          'Accuracy': pd.Series(dtype='float')},
                                         index = algorithm_list)

# Iterate over our model types
for algorithm in algorithm_list:
    # Load the trained model from file (saved at the end of training)
    with open('models/'+algorithm+'.pkl','rb') as f:
        trained_model = pickle.load(f)
    
    # Initialize the tracker
    tracker = OfflineEmissionsTracker(log_level="error", country_iso_code="IRL")
    
    # Start the tracker
    tracker.start()
    
    try:
        # Run the model on the test dataset
        predicted_output = trained_model.predict(test_features)

        # Compute the accuracy
        accuracy = accuracy_score(test_label, predicted_output)

    finally:
        # Stop the tracker and get the emissions
        emissions = tracker.stop()
        
    # Save results
    eval_algorithm_comparison.at[algorithm, 'Evaluation Emissions [kg of CO2 eq.]'] = emissions 
    eval_algorithm_comparison.at[algorithm, 'Accuracy'] = accuracy 

# Export to CSV
# eval_algorithm_comparison.to_csv("res/eval_algorithm_comparison.csv")

# Display
display(eval_algorithm_comparison)
# List of the model types we want to compare
algorithm_list = ["Random forest", "K-nearest neighbors", "Logistic regression", "Multi-layer perceptron"]

# Percentages of training data to use
prop_data = [60, 70, 80, 90]

# Create a list to store the results
rows_list = []

# Iterate over data proportions
for prop in prop_data:

    # Split dataset
    train_features, test_features, train_label, test_label = train_test_split(features, label, train_size=prop/100, test_size=0.1, random_state=30)
    
    # Iterate over our model types
    for algorithm in algorithm_list:
        
        # Initialize the tracker
        tracker = OfflineEmissionsTracker(log_level="error", country_iso_code="IRL")
        
        # Start the tracker
        tracker.start()
        
        try:
            # Train the ML model
            trained_model = train_model(algorithm, train_features, train_label)
            
        finally:
            # Stop the tracker and get the emissions
            emissions = tracker.stop()
    
        # Run the model on the test dataset
        predicted_output = trained_model.predict(test_features)

        # Compute the accuracy
        accuracy = accuracy_score(test_label, predicted_output)

        # Save results
        dict_data = {
            'Algorithm': algorithm,
            '% of original dataset': prop,
            'Training Emissions [kg of CO2 eq.]': emissions,
            'Accuracy': accuracy
        }
        print(dict_data)
        rows_list.append(dict_data)

# Resulting dataframe
training_results = pd.DataFrame(rows_list)     

# Export to CSV
# training_results.to_csv("res/training_results.csv")

# Display
training_results