Initial Model Fit
Now that we have prepared our data, the time has come to train our algorithm. We will start by splitting our data into training and testing sets, then train a Logistic Regression model as a starting point for our analysis.
Aufgabe
Swipe to start coding
- Split the data into training and test sets (75% to 25%, respectively).
- Use the appropriate method to train the Logistic Regression model.
- Make predictions using the Logistic Regression model on the test set.
Lösung
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(texts_vectorized, news['class'], test_size=0.25)
lr = LogisticRegression()
# Train the Logistic Regression model
lr.fit(X_train, y_train)
# Make predictions on the test set
pred_lr = lr.predict(X_test)
lr.score(X_test, y_test)
Mark tasks as Completed
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 5
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen