擬合模型
某大學提供了一組資料,顯示讀書時數與學生在特定測驗中的分數之間存在關係。
你可以透過變數 hours_of_study 和 scores 存取這些資料。請使用線性模型從資料中學習。
本練習屬於課程
Python 機率基礎
練習說明
- 從
scipy.stats匯入linregress()函式。 - 使用變數
hours_of_study和scores中提供的資料來擬合一個線性模型。 - 列印參數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the linregress() function
from scipy.stats import ____
# Get the model parameters
slope, intercept, r_value, p_value, std_err = ____(____, ____)
# Print the linear model parameters
print('slope:', ____)
print('intercept:', ____)