LogisticRegression Regularization AI Lab 방 성 혁. Job Flow [ex2data.txt] Format [118 by 3] mapFeature function [ mapped_x ][ y ] Format [118 by 15] … [118.

Slides:



Advertisements
Similar presentations
1 Regression as Moment Structure. 2 Regression Equation Y =  X + v Observable Variables Y z = X Moment matrix  YY  YX  =  YX  XX Moment structure.
Advertisements

Machine Learning and Data Mining Linear regression
Linear Regression.
Regularization David Kauchak CS 451 – Fall 2013.
ETHEM ALPAYDIN © The MIT Press, Lecture Slides for.
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Machine Learning & Data Mining CS/CNS/EE 155 Lecture 2: Review Part 2.
Indian Statistical Institute Kolkata
The loss function, the normal equation,
Logistics Course reviews Project report deadline: March 16 Poster session guidelines: – 2.5 minutes per poster (3 hrs / 55 minus overhead) – presentations.
Lecture 14 – Neural Networks
The Nature of Statistical Learning Theory by V. Vapnik
x – independent variable (input)
Learning From Data Chichang Jou Tamkang University.
Today Wrap up of probability Vectors, Matrices. Calculus
More Machine Learning Linear Regression Squared Error L1 and L2 Regularization Gradient Descent.
Hybrid AI & Machine Learning Systems Using Ne ural Network and Subsumption Architecture Libraries By Logan Kearsley.
Hybrid AI & Machine Learning Systems Using Ne ural Networks and Subsumption Architecture By Logan Kearsley.
ISCG8025 Machine Learning for Intelligent Data and Information Processing Week 2B *Courtesy of Associate Professor Andrew Ng’s Notes, Stanford University.
Mathematical formulation XIAO LIYING. Mathematical formulation.
ISCG8025 Machine Learning for Intelligent Data and Information Processing Week 3 Practical Notes Regularisation *Courtesy of Associate Professor Andrew.
ICS 178 Introduction Machine Learning & data Mining Instructor max Welling Lecture 6: Logistic Regression.
M Machine Learning F# and Accord.net. Alena Dzenisenka Software architect at Luxoft Poland Member of F# Software Foundation Board of Trustees Researcher.
CS 782 – Machine Learning Lecture 4 Linear Models for Classification  Probabilistic generative models  Probabilistic discriminative models.
CSE 446 Logistic Regression Winter 2012 Dan Weld Some slides from Carlos Guestrin, Luke Zettlemoyer.
Dimensionality Reduction Motivation I: Data Compression Machine Learning.
The problem of overfitting
Regularization (Additional)
Linear Models for Classification
M Machine Learning F# and Accord.net.
Over-fitting and Regularization Chapter 4 textbook Lectures 11 and 12 on amlbook.com.
Neural Networks Vladimir Pleskonjić 3188/ /20 Vladimir Pleskonjić General Feedforward neural networks Inputs are numeric features Outputs are in.
Education 793 Class Notes Inference and Hypothesis Testing Using the Normal Distribution 8 October 2003.
Competition II: Springleaf Sha Li (Team leader) Xiaoyan Chong, Minglu Ma, Yue Wang CAMCOS Fall 2015 San Jose State University.
Machine Learning CUNY Graduate Center Lecture 6: Linear Regression II.
Support Vector Machines Optimization objective Machine Learning.
Neural Networks References: “Artificial Intelligence for Games” "Artificial Intelligence: A new Synthesis"
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Tensorflow Tutorial Homin Yoon.
Machine Learning & Deep Learning
Basic operators - strings
Intro to NLP and Deep Learning
Load Balancing: List Scheduling
Announcements HW4 due today (11:59pm) HW5 out today (due 11/17 11:59pm)
Basic machine learning background with Python scikit-learn
Logistic Regression Classification Machine Learning.
Tensorflow in Deep Learning
Introduction to Tensorflow
Statistical Inference about Regression
Machine Learning Math Essentials Part 2
The Bias Variance Tradeoff and Regularization
Contact: Machine Learning – (Linear) Regression Wilson Mckerrow (Fenyo lab postdoc) Contact:
Overfitting and Underfitting
雲端計算.
Support Vector Machine I
Basis Expansions and Generalized Additive Models (2)
Artificial Neural Networks
Presented By :- Ankur Mali IST 597
Softmax Classifier.
The Math of Machine Learning
National Central University, Taiwan
Tensorflow Lecture 박 영 택 컴퓨터학부.
Load Balancing: List Scheduling
Multiple features Linear Regression with multiple variables
Multiple features Linear Regression with multiple variables
Image recognition.
Logistic Regression Geoff Hulten.
Patterson: Chap 1 A Review of Machine Learning
Machine Learning for Cyber
Presentation transcript:

LogisticRegression Regularization AI Lab 방 성 혁

Job Flow [ex2data.txt] Format [118 by 3] mapFeature function [ mapped_x ][ y ] Format [118 by 15] … [118 by 1] To make over-fit model [ mapped_x ] Format [118 by 15] … Get h(x) [Cost function with regularization term] Cost Optimize minimized Cost x2000 [result analysis]

Step #1. Import Library & Load data import tensorflow as tf import numpy as np xy = np.genfromtxt("ex2data.txt", unpack=True, dtype='float32') cf ) Case if unpack=True else if (unpack=False) First, tensorflow and numpy package should be imported Load “ex2data.txt”, col as row, data type = float ex2data.txt … unpack = True unpack = False [3 by 118] matrix [118 by 3] matrix

Step #2. mapFeature  Separate feature and real-data  To make over-fitted data, the defined function below will generate more complex features def mapFeature(x1, x2): degree = 4 out = np.ones(x1.shape) for i in range(1, degree+1): for j in range(0, i+1): out = np.c_[out, (x1**(i-j) * x2**j)] return out x = xy[0:-1] y = xy[-1] y = y.reshape(1,118) Shape of x : 2 by 118 Shape of y : 1 by 118 mapped_x = mapFeature(x[0], x[1]) Shape of mapped_x : 15 by … …………

Step #3. Declare placeholder & variable X = tf.placeholder(tf.float32) Y = tf.placeholder(tf.float32) #W = initial weight for data, len(xmap) = 15 #W = tf.Variable(tf.random_uniform([1,len(mapped_x)], -1, 1)) #rand_uniform var 1 by 15 W = tf.Variable(tf.zeros([1,len(mapped_x)]) + 0.1) place holder for mapped_x place holder for y Initial weight(theta) as 0.1 Cf) placeholder : feed actual values when Session runs

Step #4. Hypothesis h = tf.matmul(W, X) hypothesis = tf.sigmoid(h) Cf) sigmoid function 1 by 118 since (1 by 15)*(15 by 118) 1 by 118 the same dimension with h

Step #5. Cost Function & Regularization # Regularization term lambda_value = 0.1 length = len(np.transpose(mapped_x)) reg = (lambda_value/(2*length)) * tf.reduce_sum(W[0,1:]*W[0,1:]) cost = -tf.reduce_mean(Y*tf.log(hypothesis) + (1-Y)*tf.log(1-hypothesis)) + reg Cost Function of logistic regression with regularization term

Step #6. Tensorflow GradientDescentOptimizer  Tensorflow offers several machine learning libraries.  “GradientDescentOptimizer” is one of them.  Optimizer takes a parameter, learning rate “alpha”  Function “minimize” optimizes the cost from cost function a = tf.Variable(0.01) optimizer = tf.train.GradientDescentOptimizer(a) train = optimizer.minimize(cost)

Step #7. Cost Optimization  The optimization is done with 2000-iteration of gradient descent Cost Optimize minimized Cost x2000 with tf.Session() as sess: sess.run(tf.initialize_all_variables()) print "Iteration | cost" for i in xrange(2001): sess.run(train, feed_dict={X:mapped_x, Y:y}) if i % 200 == 0: print i,"|", sess.run(cost, feed_dict={X:mapped_x, Y:y}) 1)When using tensorflow variable, all defined variables must be initialized 2)Actual values are fed when Session runs

Step #8. Cost Comparison Cost variance with regularization cost = -tf.reduce_mean(Y*tf.log(hypothesis) + (1-Y)*tf.log(1-hypothesis)) + reg Cost variance without regularization cost = -tf.reduce_mean(Y*tf.log(hypothesis) + (1-Y)*tf.log(1-hypothesis)) Without reg Iteration | cost 0 | | | | | | | | | | | With reg Iteration | cost 0 | | | | | | | | | | | Conclusion 1) With training data, the cost with reg_term might be more higher than the other one. 2) With test data, the cost with reg_term would be more lower than the other one.