Logistic Regression
Last updated
Last updated
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, confusion_matrix
# 假設已有特徵 X 與標籤 y
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)
model = LogisticRegression()
model.fit(X_train, y_train)
preds = model.predict(X_val)
print("Accuracy:", accuracy_score(y_val, preds))
print("Confusion Matrix:\n", confusion_matrix(y_val, preds))