Welcome to the course!

Bộ phân loại tuyến tính với Python

Michael (Mike) Gelbart

Instructor, The University of British Columbia

Assumed knowledge

In this course we'll assume you have some prior exposure to:

  • Python, at the level of Intermediate Python
  • scikit-learn, at the level of Supervised Learning with scikit-learn
  • Supervised learning, at the level of Supervised Learning with scikit-learn
Bộ phân loại tuyến tính với Python

Fitting and predicting

import sklearn.datasets

newsgroups = sklearn.datasets.fetch_20newsgroups_vectorized()

X, y = newsgroups.data, newsgroups.target
X.shape
(11314, 130107)
y.shape
(11314,)
Bộ phân loại tuyến tính với Python

Fitting and predicting (cont.)

from sklearn.neighbors import KNeighborsClassifier

knn = KNeighborsClassifier(n_neighbors=1)
knn.fit(X,y)
y_pred = knn.predict(X)
Bộ phân loại tuyến tính với Python

Model evaluation

knn.score(X,y)
0.99991
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y)
knn.fit(X_train, y_train)

knn.score(X_test, y_test)
0.66242
Bộ phân loại tuyến tính với Python

Let's practice!

Bộ phân loại tuyến tính với Python

Preparing Video For Download...