Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
31 views
5 pages
Colab 2.2
Uploaded by
Hey Buddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Colab 2.2 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
31 views
5 pages
Colab 2.2
Uploaded by
Hey Buddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Colab 2.2 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Colab 2.2 For Later
You are on page 1
/ 5
Search
Fullscreen
217123, 9:14 0M E506 _Linear_Regression_MoreExamples_2.ipynb ~Colaboraiory Linear Regression More examples Inthis session, we shall lear about somelimiations of ner regression. Let us rat considera sample data, whlch willbe useful for our ty. AFinst, we tnpore the required packages fngort pandas a5 pd #the pancas Tibrary is useful for data processing 1 te foltatag python directive nelps Uo plot the graph In the notebook directly We il consider data generated by y= x where x denotes certain points in interval [0,5] x= npsarange(e5,0.8) prints") print¢"y:"ay) sample date = [(69) for (ey) Sn alee] print sanple data:",sanple_ data} colunn_panes = (,°¥1] ample a = 94.080 rane(data = eaqple eats, Colvane = coluennanes) Bidereret) shiple data: ((0.8, 0.2), (8.1, @.6xe99ee99e60000002), (2.2, e.esopezeeeeeeeG0e1), (2. 2e888eGG0009R—RRE, .eFeGe0—R=z=N0IEe2), (0.4, 2.1 ‘The dataset contains a predictor and response variable Sanple_abend() © 00 000 + 01 001 303 099 404 016 print(sanple¢F) 18 npe:iolab research google. convdrive/JeoWz2Ua\KS8SyecailkNO4nE72qXUpU)?authuser="HecrllTo=g6PRIAMDMEgG&orntMod217123, 9:14 0M E506 _Linear_Regression_MoreExamples_2.ipynb -Colaboraiory Seeing the data as mere numbers might not be interesting. So let us use some graphical ways to visualize the data, ‘the WIN] plot 2 scatter plot of the dts plt-seatter (sample dF(°X"], sampte dFl°Y"}) ple tithe “Sanpte Gata |X vs ¥") putsadavel(%) ple-ylavel("Y") ple-show0) 7 Sample bata xvsv Question: ts the trend linear (0?) at east linea looking? npe:iolab research google. convdrive/JeoWz2Ua\KS8SyecailkNO4nE72qXUpU)?authuser="HecrllTo=g6PRIAMDMEgG&orntMod 216217123, 9:14 0M E506 _Linear_Regression_MoreExamples_2.ipynb -Colaboraiory Computing fy, J; for the Anscombe data set 2 : Let us now compute beta, and beta.a fron the anscanbe data Set 2 f= len(sanple-af-index) thuwer of data points in the data set Drint(*nunber of data points im the asta set: "sn} sist Tet us conpute x por and yar for {An angen): daccess each row for the data set ‘a.bar se float(sanpie_df-Sat{1,0]) faccess elenent at X coluan Yyibar Se #loat(sanpie_of-tat{1,2)) faccess element at Y column Prine("x bar:"sxLbary "y bar:"s¥_ bar) for {in range(n): taccess each row fron the date set Ssigna_sx t= (Float(sanole_¢.43t(1,0]) ~ %bar)**2 teowuting (x"L - xbar)2 Signa_ay + (Fleat(Sanole_ ef 29t(1,0]) ~ bar) * (Float(sanple-et.tat(iy1})-y_bar) #eorputing (wel print" signees" shana, "stgnm 99" sien 39) how we can compute beta, and betas beta 2 = slips ny/signe_ x betale = y.bar'~ beta i x bar print¢"osta_e:", bete_e, “er: 1, beta) Plotting the regression line Having computed and, we willow plot the line y = f+ By alg with the points inthe dataset. for 4 An ranger): daccess cath row fron the data set Xi = Aoat(sanple df. iat[1,e]) faccess elenent at X column ranean x ainp.Linspace(x nin, a, 108) aereates 2 series of points 49 x axis y= bec 1ete 8 ple-plotix, y, "=F", labele'regression Line") ple-seatter(saeple dX], semple-d#1°Y"]) npe:iolab research google. convdrive/JeoW2Ua\KS8SyecailkNO4nE72qXUpU/?authuser="scrllTo=g6PRIAMDMEgGBorntMod xpanyty.ar) 36217123, 9:14 0M E506 _Linear_Regression_MoreExamples_2.ipynb -Colaboraiory ple. titte“Sampte data X vs ¥ Regression") putsadaped(%") ple-ylavel("Y") lt legend(Loce"upper Letty ‘olt-erta() ple. stow) Sample data x ve ¥ Regression Residual Plot Sometimes it would be usefl to pot the err (1) residual e versus the fited values J = fa + Bp. viduals ist = 1) Yar © in manga(n): aaecess each row for the dats aot ‘Lt + float (sample ef.at{i,e]) daccess element at X column yi = Alout(sanple_ef.at{1,4]) daccess element at ¥ colum Yyopred_t = neta. * x1 + beta e teonpute the prediction obtained using the regression coefficients el = yA = y.pred.s Beonpute the difference between the actual observation y-4 and prediction y_pred_4 ‘plot the resicuals « plt.seatter(sarple_a*["V"], «1 residuels_ 1st color ple titte("Ressaual plot”) plt-adavel("Y responses") plt-ylavel(*Restauals") piteris) ple-stow() ry Residual plot Note thatthe residual vs response plot shows a significant trend of residual behavior as y varies. Residue vs Predictor Plot Let us pot the residue ve predictor. plot the residuals e4 against the predictors 1 ple.seatter(sarple 4¢{'X'], ¢_i_resicuals_list,color="g') ple-title("Resieual vs, preeictar plot") plt-xlavel ("erediccor x") pit ylavet("aesteuats") npe:iolab research google. convdrive/JeoW2Ua\KS8SyecailkNO4NE72qXUpU/?authuser="HecrllTo=g6PRIAMDMEgG&orntMod resicuals_list-append(e_1) fappend the value of ei to the list 46217123, 9:14 0M E506 _Linear_Regression_MoreExamples_2.ipynb -Colaboraiory pitertaey pltshont) esidal vs. reictr pot 2, "Note thatthe residual vs predictor plot also shows a sigaificant rend of residual behavior as 2 varies, Ths indicates that the inear model assumption used to fit the data might nat be @ goad assumption, Letus now compute the sample correlation. rote that stgna AY apd signa OC nave already been computed ance we will now conpute signa ¥¥ tniso note that y_bar As computed before stay = 0 for i in range(n): #access eath row fron the dats set yA = float (sample ef-at[t,1]) aaccess elenent at ¥ colum Sigmagy o= Ocisysbar)"2 rint("signe_yy:", signe yy) sTyen we WLLL conpute the sanple correlation sample_conrelation = signa_xy/(np.sqrt(signa_ee * signe_yy)) print( "sample correlation" ysample_correlatson) signa: 2673. 30525000002 Sanpla Correlation: @,9870508513356978 Letus compute R?, ote that sun of squared residuals needs to be computes sum_se_restvats = @ for i in ranger): #access each row frov the date set ALi = Alost(sanple of. iat{i,e]) #access elenent st X colum 91k = Aloat(sanple_ef-iatTi,a]) aaccess elenent at ¥ colum Yipred t's beta Ieiet + bets 8 Son_sguresiduals 40 (-S-y.pned 1)*"2 Print( "sun of Squared resiguats:*, sum sq_restdusts) sTyen we WLLL conpute the R12 quantity sq’ L-sun sq_resicvals/signs_vy prine°2:"s8_s8) + Note: ‘The R? valu is quite high which might seem to indicate thatthe fis good enough. However taken together wit residual pots, we see that espite having good R? value, the inear model assumptions questionable. Exercises: npe:iolab research google. convrive/JeoWzUa\KS8SyecailkNO4nE72qXUpU/?authuser="HecrllTo=g6PRIAMDMEgGBorntMod 56
You might also like
NB 12
PDF
No ratings yet
NB 12
34 pages
Lecture 11 Regression
PDF
No ratings yet
Lecture 11 Regression
53 pages
Chapter 14
PDF
No ratings yet
Chapter 14
18 pages
Data Science Chapitre 2
PDF
No ratings yet
Data Science Chapitre 2
98 pages
Me310 5 Regression PDF
PDF
No ratings yet
Me310 5 Regression PDF
15 pages
H-311 Linear Regression Analysis With R
PDF
100% (1)
H-311 Linear Regression Analysis With R
71 pages
Lab 8
PDF
No ratings yet
Lab 8
13 pages
Regression Analysis With Scilab
PDF
No ratings yet
Regression Analysis With Scilab
57 pages
Experiment No.:1: Program
PDF
No ratings yet
Experiment No.:1: Program
7 pages
Machine Learning Assignment
PDF
No ratings yet
Machine Learning Assignment
2 pages
Linear Regression
PDF
100% (2)
Linear Regression
228 pages
BN2102 7-10
PDF
No ratings yet
BN2102 7-10
24 pages
Objects Oriented Programming OOP
PDF
No ratings yet
Objects Oriented Programming OOP
67 pages
Multiple Linear Regression
PDF
100% (1)
Multiple Linear Regression
14 pages
Lab1 Code PDF
PDF
No ratings yet
Lab1 Code PDF
3 pages
21brs1474 ML Lab 2
PDF
No ratings yet
21brs1474 ML Lab 2
25 pages
Linear Regression
PDF
No ratings yet
Linear Regression
14 pages
Homework4 1
PDF
No ratings yet
Homework4 1
10 pages
ML Practical File
PDF
100% (2)
ML Practical File
43 pages
ML Lab-3
PDF
No ratings yet
ML Lab-3
14 pages
19BCS2059 DL1
PDF
No ratings yet
19BCS2059 DL1
4 pages
Assignment No.4 - (20-Ele-68)
PDF
No ratings yet
Assignment No.4 - (20-Ele-68)
17 pages
Regression
PDF
No ratings yet
Regression
7 pages
Machine Learning Lab: Raheel Aslam (74-FET/BSEE/F16)
PDF
No ratings yet
Machine Learning Lab: Raheel Aslam (74-FET/BSEE/F16)
4 pages
Lab 4
PDF
No ratings yet
Lab 4
7 pages
Linear Regression Code
PDF
No ratings yet
Linear Regression Code
5 pages
DatA414 Prac 2 Linear Regression 2024.pdfasisipho
PDF
No ratings yet
DatA414 Prac 2 Linear Regression 2024.pdfasisipho
21 pages
Simple Linear Regression
PDF
No ratings yet
Simple Linear Regression
5 pages
3 Regression
PDF
No ratings yet
3 Regression
26 pages
Using R For Linear Regression
PDF
No ratings yet
Using R For Linear Regression
9 pages
R Notes
PDF
No ratings yet
R Notes
4 pages
AI Lab9
PDF
No ratings yet
AI Lab9
5 pages
ml2020 Pythonlab02
PDF
No ratings yet
ml2020 Pythonlab02
3 pages
Experiment 1
PDF
No ratings yet
Experiment 1
17 pages
Machine Learning Lab Notes
PDF
No ratings yet
Machine Learning Lab Notes
3 pages
Linear Regression - Numpy and Sklearn
PDF
No ratings yet
Linear Regression - Numpy and Sklearn
7 pages
Expt5 Group7
PDF
No ratings yet
Expt5 Group7
15 pages
ML Unit
PDF
No ratings yet
ML Unit
23 pages
Regression Anallysis Hands0n 1
PDF
100% (1)
Regression Anallysis Hands0n 1
3 pages
Week 2 MrSumanBera HandsOn
PDF
No ratings yet
Week 2 MrSumanBera HandsOn
9 pages
Lab 10 Forest Regression
PDF
No ratings yet
Lab 10 Forest Regression
5 pages
DA Lab ANSWERS
PDF
No ratings yet
DA Lab ANSWERS
10 pages
Simple Linear Regression Sample
PDF
No ratings yet
Simple Linear Regression Sample
55 pages
Unit 2 Regression Analysis
PDF
No ratings yet
Unit 2 Regression Analysis
16 pages
Dav Exp
PDF
No ratings yet
Dav Exp
11 pages
Assignment 7
PDF
No ratings yet
Assignment 7
4 pages
Linear Regression
PDF
No ratings yet
Linear Regression
4 pages
Regression Model
PDF
No ratings yet
Regression Model
6 pages
15.simple Linear Regression-530
PDF
No ratings yet
15.simple Linear Regression-530
54 pages
Lab 11,12
PDF
No ratings yet
Lab 11,12
7 pages
Lecture-2 Unit 2
PDF
No ratings yet
Lecture-2 Unit 2
56 pages
Exp 4 - LM
PDF
No ratings yet
Exp 4 - LM
5 pages
ICT 2102-Curve-Fitting and Interpolation
PDF
No ratings yet
ICT 2102-Curve-Fitting and Interpolation
29 pages
Lab 6 - Linear Regression and Multiple Linear Regression
PDF
No ratings yet
Lab 6 - Linear Regression and Multiple Linear Regression
12 pages
20mia1006 FDA LAB REGRESSION TYPES
PDF
No ratings yet
20mia1006 FDA LAB REGRESSION TYPES
11 pages
Lect 10 Regression
PDF
No ratings yet
Lect 10 Regression
7 pages
Datascience Lab
PDF
No ratings yet
Datascience Lab
24 pages