Linear Classifiers in Python: Chapter2
Linear Classifiers in Python: Chapter2
Classifiers in Python
Linear classifiers:
prediction equations
Dot products
In [1]: x = np.arange(3)
In [2]: x
Out[2]: array([0, 1, 2])
In [3]: y = np.arange(3,6)
In [4]: y
Out[4]: array([3, 4, 5])
In [5]: x*y
Out[5]: array([0, 4, 10])
In [6]: np.sum(x*y)
Out[6]: 14
In [7]: x@y
Out[7]: 14
x@y is called the dot product of x and y , and is written x ⋅ y.
DataCamp Linear Classifiers in Python
In [1]: lr = LogisticRegression()
In [2]: lr.fit(X,y)
In [3]: lr.predict(X)[10]
Out[3]: 0
In [4]: lr.predict(X)[20]
Out[4]: 1
In [5]: lr.coef_ @ X[10] + lr.intercept_ # raw model output
Out[5]: array([-33.78572166])
In [6]: lr.coef_ @ X[20] + lr.intercept_ # raw model output
Out[6]: array([ 0.08050621])
DataCamp Linear Classifiers in Python
Let's practice!
DataCamp Linear Classifiers in Python
What is a loss
function?
Michael Gelbart
Instructor
The University of British Columbia
DataCamp Linear Classifiers in Python
function.
DataCamp Linear Classifiers in Python
Minimizing a loss
In [1]: from scipy.optimize import minimize
Let's practice!
DataCamp Linear Classifiers in Python
Let's practice!