Predict the Output
Intermediate · Predict the output · from Python Classification: Build a Classifier with scikit-learn
From the lesson: Python Classification: Build a Classifier with scikit-learn
Your email inbox sorts messages into "spam" or "not spam." A bank flags transactions as "fraudulent" or "legitimate." A doctor classifies a tumor as "benign" or "malignant." These are all classification problems - the model predicts which category something belongs to.
Read the lessonWhat shape will predict_proba() return for 40 test samples in a binary classification problem?
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
X, y = make_classification(n_samples=200, n_features=4,
random_state=42)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42)
model = LogisticRegression(random_state=42)
model.fit(X_train, y_train)
print(model.predict_proba(X_test).shape)
More Classification exercises
- Train a Logistic Regression ClassifierIntermediate
- Build a Decision Tree ClassifierIntermediate
- Fix the KNN BugIntermediate
- Read a Confusion MatrixIntermediate
- Compare Three ClassifiersIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz