Logistic Regression
使用上一個練習的資料,現在你要訓練一個機器學習模型。
依照最佳實務,特徵資料已提供為 X_train,標籤已載入為 y_train。
部分資料另提供為 X_test。你將在本章後面學到如何正確建立這些變數。
本練習屬於課程
使用 Python 分析 IoT 資料
練習說明
- 從
sklearn.linear_model匯入LogisticRegression。 - 將模型初始化為
logreg。 - 使用標籤
y_train將模型擬合到X_train。 - 使用
X_test預測部分類別。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import LogisticRegression
from ____ import ____
# Initialize the model
logreg = ____
# Fit the model
____.____(____, ____)
# Predict classes
print(____.____(____))