welcome to the co u rse
play

Welcome to the co u rse ! L IN E AR C L ASSIFIE R S IN P YTH ON - PowerPoint PPT Presentation

Welcome to the co u rse ! L IN E AR C L ASSIFIE R S IN P YTH ON Michael ( Mike ) Gelbart Instr u ctor , The Uni v ersit y of British Col u mbia Ass u med kno w ledge In this co u rse w e ' ll ass u me y o u ha v e some prior e x pos u re to : P y


  1. Welcome to the co u rse ! L IN E AR C L ASSIFIE R S IN P YTH ON Michael ( Mike ) Gelbart Instr u ctor , The Uni v ersit y of British Col u mbia

  2. Ass u med kno w ledge In this co u rse w e ' ll ass u me y o u ha v e some prior e x pos u re to : P y thon , at the le v el of Intermediate P y thon for Data Science scikit - learn , at the le v el of S u per v ised Learning w ith scikit - learn s u per v ised learning , at the le v el of S u per v ised Learning w ith scikit - learn LINEAR CLASSIFIERS IN PYTHON

  3. 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

  4. 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

  5. Model e v al u ation 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

  6. Let ' s practice ! L IN E AR C L ASSIFIE R S IN P YTH ON

  7. Appl y ing logistic regression and SVM L IN E AR C L ASSIFIE R S IN P YTH ON Michael ( Mike ) Gelbart Instr u ctor , The Uni v ersit y of British Col u mbia

  8. Using LogisticRegression from sklearn.linear_model import LogisticRegression lr = LogisticRegression() lr.fit(X_train, y_train) lr.predict(X_test) lr.score(X_test, y_test) LINEAR CLASSIFIERS IN PYTHON

  9. LogisticRegression e x ample import sklearn.datasets wine = sklearn.datasets.load_wine() from sklearn.linear_model import LogisticRegression lr = LogisticRegression() lr.fit(wine.data, wine.target) lr.score(wine.data, wine.target) 0.972 lr.predict_proba(wine.data[:1]) array([[ 9.951e-01, 4.357e-03, 5.339e-04]]) LINEAR CLASSIFIERS IN PYTHON

  10. Using LinearSVC LinearSVC w orks the same w a y: import sklearn.datasets wine = sklearn.datasets.load_wine() from sklearn.svm import LinearSVC svm = LinearSVC() svm.fit(wine.data, wine.target) svm.score(wine.data, wine.target) 0.893 LINEAR CLASSIFIERS IN PYTHON

  11. Using SVC import sklearn.datasets wine = sklearn.datasets.load_wine() from sklearn.svm import SVC svm = SVC() # default hyperparameters svm.fit(wine.data, wine.target); svm.score(wine.data, wine.target) 1. Model comple x it y re v ie w: Under � � ing : model is too simple , lo w training acc u rac y O v er � � ing : model is too comple x, lo w test acc u rac y LINEAR CLASSIFIERS IN PYTHON

  12. Let ' s practice ! L IN E AR C L ASSIFIE R S IN P YTH ON

  13. Linear decision bo u ndaries L IN E AR C L ASSIFIE R S IN P YTH ON Michael ( Mike ) Gelbart Instr u ctor , The Uni v ersit y of British Col u mbia

  14. Linear decision bo u ndaries LINEAR CLASSIFIERS IN PYTHON

  15. Definitions Vocab u lar y: classi � cation : learning to predict categories decision bo u ndar y : the s u rface separating di � erent predicted classes linear classi � er : a classi � er that learns linear decision bo u ndaries e . g ., logistic regression , linear SVM linearl y separable : a data set can be perfectl y e x plained b y a linear classi � er LINEAR CLASSIFIERS IN PYTHON

  16. Linearl y separable data LINEAR CLASSIFIERS IN PYTHON

  17. Let ' s practice ! L IN E AR C L ASSIFIE R S IN P YTH ON

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend