開始使用免費開始

擬合模型

某大學提供了一組資料,顯示讀書時數與學生在特定測驗中的分數之間存在關係。

你可以透過變數 hours_of_studyscores 存取這些資料。請使用線性模型從資料中學習。

本練習屬於課程

Python 機率基礎

檢視課程

練習說明

  • scipy.stats 匯入 linregress() 函式。
  • 使用變數 hours_of_studyscores 中提供的資料來擬合一個線性模型。
  • 列印參數。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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:', ____)
編輯並執行程式碼