AI_Assignment_checker / uploads /assignment_10.py
Za-heer's picture
fixed browser error
f6086a9
raw
history blame contribute delete
720 Bytes
# Assignment 10: Train-Test Split and Evaluation
# Split dataset and evaluate a model
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
import numpy as np
# Synthetic dataset
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 0, 1, 1])
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# Train model
model = LogisticRegression()
model.fit(X_train, y_train)
# Evaluate
predictions = model.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, predictions)}")
print(f"Confusion Matrix: {confusion_matrix(y_test, predictions)}") # Error: confusion_matrix not imported