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()
Please 'Accept as answer' and Upvote if it helped so that it can help others in the community looking for help on similar topics.