建立分類模型
用肉眼比對差異有助於建立對資料的直覺,但現在來試試看能不能用模型把這件事系統化。這個練習中,你會把每一次重複視為一個資料點,並把每個時間點視為一個特徵,來訓練一個分類器,只用原始資料來預測心跳是異常還是正常。
我們已經把兩個 DataFrame(normal 與 abnormal)切分為 X_train、X_test、y_train 和 y_test。
本練習屬於課程
Python 的時間序列資料機器學習
練習說明
- 建立一個 Linear SVC 模型實例,並用訓練資料來訓練模型。
- 使用測試資料在模型上產生預測。
- 使用提供的程式碼為模型計分。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from sklearn.svm import LinearSVC
# Initialize and fit the model
model = ____
model.____
# Generate predictions and score them manually
predictions = model.____
print(sum(predictions == y_test.squeeze()) / len(y_test))