Imported codes does not work for learning path "Foundations of data science for machine learning"

Yuan Qing Tan 20 Reputation points
2025-04-13T12:25:35.79+00:00

Been following the learning path Foundations of data science for machine learning

but whenever the exercise involves custom imported codes, the code will not run.

User's image

User's image

This question is related to the following Learning Module

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,335 questions
{count} votes

Accepted answer
  1. Pavankumar Purilla 8,335 Reputation points Microsoft External Staff Moderator
    2025-04-14T07:01:45.7466667+00:00

    Hi Yuan Qing Tan,
    You're encountering issues in the Microsoft Learn "Foundations of Data Science for Machine Learning" module because the exercises rely on a custom module named graphing, which is not available in the learning environment. This causes import errors, such as "Import 'graphing' could not be resolved," and leads to further problems when trying to run visualizations. Additionally, the visualization errors you're seeing, such as "this.Plotly.newPlot is not a function" or "Cannot read properties of undefined (reading 'Config')," suggest that the interactive Plotly library used by the platform is either misconfigured or not fully supported in the notebook environment. To work around this, you can manually replace the graphing.scatter_2D() function with standard Python libraries such as matplotlib to create scatter plots and regression lines.

    import matplotlib.pyplot as plt
    import numpy as np
    
    for feature in ["male", "age", "protein_content_of_last_meal", "body_fat_percentage"]:
        formula = "core_temperature ~ " + feature
        simple_model = smf.ols(formula=formula, data=dataset).fit()
    
        print(feature)
        print("R-squared:", simple_model.rsquared)
    
        # Plot manually
        plt.figure()
        plt.scatter(dataset[feature], dataset["core_temperature"], label="Data")
        
        # Regression line
        x_vals = np.linspace(dataset[feature].min(), dataset[feature].max(), 100)
        y_vals = simple_model.params[1] * x_vals + simple_model.params[0]
        plt.plot(x_vals, y_vals, color='red', label="Regression Line")
        
        plt.title(f"{feature} vs Core Temperature")
        plt.xlabel(feature)
        plt.ylabel("core_temperature")
        plt.legend()
        plt.show()
    
    

    User's image

    Please 'Accept as answer' and Upvote if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.