3 views

Uploaded by Ryan Goh

lnr_rgs

- ENR 304 Lab 4 Assignment
- NDT methods on steel buildings
- Cook Weisberg Residuals and Influence
- Mitrushina (2005) Rey O Meta Norms
- Robust Regression
- A notes sheet for Econometrics
- MANAGEMENT OF ORGANIZATIONAL LEARNING TO ENHANCE ORGANIZATIONAL COMPETENCIES DEVELOPMENT IN MANUFACTURING INDUSTRIES
- nalsisi 2.docx
- dougherty5e_C01G01_2015_12_18
- Simple Linear Regression-Part 1
- Chap 13
- Chapter 15 Inference for Regressio.n
- ABB Electric Data (Customer Choice)
- STATA
- 59
- fdfhklklfnl.xlsx
- The Unscrambler Methods
- HILDA-SR-2017.pdf
- تحرير التجارة الخارجية وأثره على معدل النمو الاقتصادي في سوريا
- Chapter 4

You are on page 1of 4

LINEAR REGRESSION

#https://stackoverflow.com/questions/43027980/purpose-of-matplotlib-inline

import numpy as np

import matplotlib.pyplot as plt

csv = 'https://www.dropbox.com/s/oqoyy9p849ewzt2/linear.csv?dl=1'

data = np.genfromtxt(csv,delimiter=',')

X = data[:,1:]

Y = data[:,0]

import theano.tensor as T

d = X.shape[1] #columns of features

n = X.shape[0] #no. of training samples

learn_rate = 0.5

y = T.vector(name='y') #response vector

w = theano.shared(np.zeros((d,1)),name='w')

#https://www.quora.com/What-is-the-meaning-and-benefit-of-shared-variables-in-Theano

risk = T.sum((T.dot(x,w).T-y)**2)/2/n

#https://stackoverflow.com/questions/38185601/theano-using-dot-t-at-the-end-of-a-dot-pr

grad_risk = T.grad(risk,wrt=w) #gradient of risk

train_model = theano.function(

inputs=[],

outputs=risk,

updates=[(w,w-learn_rate*grad_risk)],

givens={x:X,y:Y}

)

n_steps = 50

for i in range(n_steps):

print(train_model())

2.619322008585456

0.7587559422725656

1

0.23542812224973012

0.07939576047330808

0.030096896364576606

0.013695201975103268

0.008006092308871296

0.005970446508700003

0.005225932117259178

0.004949550127903776

0.004845924776165537

0.0048068130299667704

0.004791984242871621

0.004786344307210614

0.0047841942688007875

0.0047833731708215

0.004783059133878644

0.004782938874883769

0.004782892769416027

0.004782875074349405

0.00478286827612244

0.004782865661743263

0.0047828646553662564

0.004782864267605403

0.00478286411806061

0.004782864060333996

0.004782864038030564

0.004782864029405724

0.004782864026067559

0.004782864024774452

0.004782864024273129

0.004782864024078616

0.004782864024003076

0.004782864023973726

0.004782864023962313

0.004782864023957866

0.004782864023956134

0.0047828640239554595

0.004782864023955196

0.004782864023955098

0.004782864023955059

0.004782864023955038

0.0047828640239550345

0.004782864023955031

0.004782864023955031

0.004782864023955033

0.0047828640239550285

0.004782864023955029

0.004782864023955031

0.004782864023955036

2

(a) Coefficients of vector w:

[[-0.57392068]

[ 1.35757059]

[ 0.01527565]

[-1.88288076]]

from theano.tensor.nlinalg import matrix_inverse

xt = T.matrix('xt')

x = T.matrix('x')

y = T.vector('y')

a = matrix_inverse(T.dot(xt,x))

f = theano.function([xt, x], a)

gramian = f(X.T,X)

b = T.dot(xt,y)

g = theano.function([xt, y], b)

moment = g(X.T,Y)

theta = g(gramian,moment)

print('(b) Exact optimal solution: ', theta)

print('Solution is same as coefficients of w through gradient descent')

Solution is same as coefficients of w through gradient descent

regr = linear_model.LinearRegression()

regr.fit(X, Y)

print('Coefficients: \n', regr.coef_)

print('\nSci-kit learn linear regression uses ordinary least squares regression and its

print('coefficient estimates depend on independence of features. Since the last attribu

print('is a column of ones, it makes sense that there will be an error of 0. in the coe

Coefficients:

[-0.57392068 1.35757059 0.01527565 0. ]

Sci-kit learn linear regression uses ordinary least squares regression and its

3

coefficient estimates depend on independence of features. Since the last attribute

is a column of ones, it makes sense that there will be an error of 0. in the coefficient.

- ENR 304 Lab 4 AssignmentUploaded byAliyu Sn
- NDT methods on steel buildingsUploaded byUppala Krishna Chaitanya
- Cook Weisberg Residuals and InfluenceUploaded byEnrique Slim
- Mitrushina (2005) Rey O Meta NormsUploaded byPavel Litvin
- Robust RegressionUploaded bytia84tia
- A notes sheet for EconometricsUploaded bygadihok
- MANAGEMENT OF ORGANIZATIONAL LEARNING TO ENHANCE ORGANIZATIONAL COMPETENCIES DEVELOPMENT IN MANUFACTURING INDUSTRIESUploaded byImpact Journals
- nalsisi 2.docxUploaded byNoviani Munsir
- dougherty5e_C01G01_2015_12_18Uploaded byHarini Chandrasekar
- Simple Linear Regression-Part 1Uploaded byfa2heem
- Chap 13Uploaded bytista bhowmik
- Chapter 15 Inference for Regressio.nUploaded bycamillesyp
- ABB Electric Data (Customer Choice)Uploaded bybrkn
- STATAUploaded byamudaryo
- 59Uploaded byChipo Chip
- fdfhklklfnl.xlsxUploaded byal
- The Unscrambler MethodsUploaded byMostafa Afify
- HILDA-SR-2017.pdfUploaded byABC News Online
- تحرير التجارة الخارجية وأثره على معدل النمو الاقتصادي في سورياUploaded byAdibsul
- Chapter 4Uploaded byRizky Aidil Adha
- 15 Corr Regres2Uploaded byJohan Ariff
- Case solution on agricompUploaded byBadhandas
- HILDA 2017Uploaded byABC News Online
- Linear and Nonlinear Regression_Manesh MeenaUploaded bytadsrikanth_chainlu
- Linear Regression 12Uploaded byashigaik
- The Household, Income and Labour Dynamics in Australia SurveyUploaded byErin Hill
- PP-312 Method of Least SquaresUploaded bySunit Arora
- Hasil Uji Bu DwiUploaded byBertolomeus Seda
- Geoff LeyUploaded byvlabrague6426
- ch11Uploaded byAídaMariana

- Project ProposalUploaded byRyan Goh
- MIksicUploaded byRyan Goh
- The Lord of the Dance Alto SaxophoneUploaded byRyan Goh
- Rose_of_cikembang.pdfUploaded byRyan Goh
- 2017 Ml Homework 01Uploaded byRyan Goh
- Roxanne - Full Score4Uploaded byRyan Goh
- State DiagramUploaded byRyan Goh
- NSLab1Uploaded byRyan Goh
- PS5_qn4Uploaded byRyan Goh
- Prob Exam IUploaded byLBH
- Lab10Uploaded byRyan Goh
- NSLab3Uploaded byRyan Goh
- Lesson Plan Math Mass MeasurementUploaded byRyan Goh
- Holy HolyUploaded byRyan Goh
- FB358Uploaded byRyan Goh
- Marimba partUploaded byRyan Goh
- Bhagavad Gita EssayUploaded byRyan Goh
- Lab 3 CircuitUploaded byRyan Goh
- WeChatUploaded byRyan Goh
- Stravinsky Symphony of Psalm Full ScoreUploaded byRyan Goh
- GameUploaded byRyan Goh
- CompositionUploaded byRyan Goh
- Presentation of the Self PART 3Uploaded byRyan Goh

- Chapter III Results and DiscussionUploaded byShairuz Caesar Briones Dugay
- 1 Simple Linear Regression ModelUploaded byshawkt
- ITC Lecture13Uploaded byali
- Verdoorn-Kaldor’s Law: an empirical analysis with time series data in the United StatesUploaded byrenilson-silva
- (Graduate Texts in Physics) Massimiliano Bonamente (Auth.)-Statistics and Analysis of Scientific Data-Springer-Verlag New York (2017)Uploaded byHernánQuiroz
- PruebaUploaded byJuan Mondá
- Regression Notes 01Uploaded byDarfElfDrizzt
- Exercises 111Uploaded byLostorageAce
- Problems econometricsUploaded byHoanglucia
- 1Uploaded byMunirah Hashim
- Stats Sample Midterm SolnsUploaded byjiosja
- ASSG2__BATCH2_GROUP4Uploaded bypranshumanu
- GAISE - Level C - August 2005 - p60-p89Uploaded byDennis Ashendorf
- 2017-Grigo-Koutsourelakis-(UNCECOMP 2017)-Probabilistic Reduced Order Modeling for Stochastic PDEUploaded byEzio Araujo
- Vol ModelingUploaded bymshchetk
- Zivot - Introduction to Computational Finance and Financial EconometricsUploaded byjrodasch
- O-Hara Et Al-2010-Do Not Log-transform Count Data-Methods in Ecology and EvolutionUploaded bychinchay07
- Factor AnalysisUploaded bySheraz Khan
- Stats week 1.pdfUploaded byDhyey Desai
- Data mining and model selectionUploaded byIlinca Maria
- Excel Guide MorganUploaded bydmrpanda9940
- homoscedasticityUploaded bycallanant
- CBE486/586 Syllabus Fall 2016Uploaded bySB216
- IPPTCh007Uploaded byRene
- _Brochure NCSS 2000.pdfUploaded bygore_11
- BA9201 Statistics for Managemant JAN 2012Uploaded bySivakumar Natarajan
- Modern Mathematical Statistics With Applications (2nd Edition)Uploaded byAlex Bond
- 08 Random Number GenerationUploaded byRupa Dn
- Presentation McqsUploaded byEngr Mujahid Iqbal
- Chi Square LectureUploaded byJasper Angeles