SLIDE 1 CS 330 - Artificial Intelligent
Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Fall 2019 1
SLIDE 2 Announcement
- Review on decision tree homework
- Reading materials posted on course website (Information
gain, Naive Bayesian and Decision Tree example)
- Quiz #3 on next Tuesday. Go over study guide.
- Literature review (bring your laptop for adding comments)
and generate group order.
SLIDE 3
Another way for Lab 2 Matrix operation
Numpy: open-source add-on module to Python that provide common mathematical and numerical routines
SLIDE 4 Numpy
#import numpy
#import numpy as np
SLIDE 5
Numpy
# a = np.array([1, 4, 5, 8], float) # type(a) Try : a[:2] Try : a[3] Try : a[0] = 5 # a = np.array([[1, 2, 3], [4, 5, 6]], float) Try: a[0,0] Try: a[-1:, -2:] Try: a.shape Try: len(a)
SLIDE 6
Numpy
# a.tolist() or list(a) # b = a.flatten() # b.reshape(3,2) Some operations like: # a+a # a*a # np.dot(a,b) # np.sqrt(a) # a.min() or a.max(), a.mean() More reading materials on course website!
SLIDE 7
Scikit-Learn: Machine learning in Python
http://scikit-learn.org/stable/ Connect to Simon server, and go to Python command mode
SLIDE 8 Scikit-Learn: Machine learning in Python
from sklearn import datasets iris = datasets.load_iris() from sklearn.naive_bayes import GaussianNB gnb = GaussianNB() y_pred = gnb.fit(iris.data, iris.target).predict(iris.data) print("Number of mislabeled points out of a total %d points : %d" % (iris.data.shape[0],(iris.target != y_pred).sum()))
SLIDE 9 Scikit-Learn: Machine learning in Python
from sklearn.datasets import load_iris from sklearn import tree iris = load_iris() clf = tree.DecisionTreeClassifier() clf = clf.fit(iris.data, iris.target) y_pred = clf.predict(iris.data) print("Number of mislabeled points out of a total %d points : %d" % (iris.data.shape[0],(iris.target != y_pred).sum()))
SLIDE 10 Scikit-Learn: Machine learning in Python
- 3. Logistic Regression Example
from sklearn.datasets import load_iris from sklearn.linear_model import LogisticRegression iris = load_iris() clf = LogisticRegression(random_state=0, solver='lbfgs', multi_class='multinomial').fit(iris.data, iris.target) y_pred = clf.predict(iris.data) print("Number of mislabeled points out of a total %d points : %d" % (iris.data.shape[0],(iris.target != y_pred).sum()))
SLIDE 11 Scikit-Learn: Machine learning in Python
- 4. Linear Regression Example
from sklearn.datasets import load_iris from sklearn.linear_model import LinearRegression iris = load_iris() clf = LinearRegression().fit(iris.data, iris.target) y_pred = clf.predict(iris.data) print("Number of mislabeled points out of a total %d points : %d" % (iris.data.shape[0],(iris.target != y_pred).sum()))
SLIDE 12
Scikit-Learn: Machine learning in Python
Lab 3: check Sakai assignment, explore sklearn at: https:// scikit-learn.org/stable/