Model validation with Python

Model validation is an important step in the machine learning process to ensure that our model is performing well on unseen data. Step 1: Splitting the data into training and testing sets.
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Step 2: Training the model on the training data.
from sklearn.linear_model import LogisticRegression

model = LogisticRegression()
model.fit(X_train, y_train)

Step 3: Making predictions on the testing data.
y_pred = model.predict(X_test)

Step 4: Evaluating the model performance using metrics such as accuracy, precision, recall, and F1 score.
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score

accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)

print("Accuracy:", accuracy)
print("Precision:", precision)
print("Recall:", recall)
print("F1 Score:", f1)

Comments

Popular posts from this blog

What are the different evaluation metrics used in machine learning?

Ten top resources for learning Python programming