Welcome to the course!

Linear Classifiers in 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
Linear Classifiers in 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,)
Linear Classifiers in Python

Fitting and predicting (cont.)

from sklearn.neighbors import KNeighborsClassifier

knn = KNeighborsClassifier(n_neighbors=1)
knn.fit(X,y)
y_pred = knn.predict(X)
Linear Classifiers in 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
Linear Classifiers in Python

Let's practice!

Linear Classifiers in Python

Preparing Video For Download...