0% found this document useful (0 votes)
10 views3 pages

Lab1 Code PDF

Lab1 of Least Squares Estimate

Uploaded by

nick4rocks13
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
0% found this document useful (0 votes)
10 views3 pages

Lab1 Code PDF

Lab1 of Least Squares Estimate

Uploaded by

nick4rocks13
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
You are on page 1/ 3
v Labt 2 seport matpioeLibepyplot 2 pt 4. oF = pe.reae_csv("pointteasurenents_Labi.csv", neater = None) 6 notsplayiay 4 = 10000; _# number of sterattons 5. = 0.001; # Leerning rate 17 ef cost funesion.x(0, by % 9): 1a deen (2 0x) 500)" (CRT 4 BY) 21 def cost function 6(0, by % 9) 2 ded (2 / 508) * (lex +8) 23 return deg 235 ef regression ks sam, sums): Benen oe = Lt nme 2 return what 25 def repression D(a.8, b.8, Ly Sunn, sums): 533 et nat_updete(e hat, b.nat) sen pemhet as bop ohoe 36 return m8, 28 for 4 in range( see) 39 Sunn 4+ cost function n(H 08.8, 4f.Sloe{ If) 42 sunb 4 cost_funetion 9(@ 6,28, .s0( 4) (0 42 for 5 Ln rangeced 43 mewn, newb = hat upeate(repression n(48, 6.9, Ly sum, sum), regression b(n.8, P.9, Ls sum, svro)) fe fort 49 ranget300) ee snoet 12) er nee(s2)) 45 sum 4 cost function n(rew.n, new.b, df-tloe[SII6], #f-éloet3}f1)) 46 san ss cont function (news, new_b, df élee[$](@], 4 Sl9e(s1/3)) 48 printinewn, news) 50 8 Create the Linear regression Line SL repression line = neq.n * of[@) = ne¥_b 53.4 Plot the ¢ata points and the Linear regression Line 54 ple.scotter(af{6], #f{2], label-"Data Points") SS ple plot(Gr[@], regression Jine, colore"red", labelef'Regression Line: y = {new.n:.24)« + (new.b:.26)') 57 8 Add Labels and Legend 58 pie-xiabei('x") 59 ple-ylobel('y") 68 pit. legend.) 62 # Show the plot 13 ple.shoe() © Data Points ° 80) — pagression Line: y= 2.ane + 2.33 . 2 2 residusls = regression Line - d¢{3) 4 = np.arange(a set.) 18 Plot che cata points, the Linear regression Line, and restevals 7 pie.scattertx, resisusis, color="blue") a 20 Afar 5 in range( se). ie pltplot((ar(e) 13 # Add Labels and Legend 1 ple-xtabel¢'x') 15 pl -ylabel(Resicvals") 17 Show the plot 2 ple-show() 21 print(-Resteuals:", residues) 1, AF{0][E}}, [regression tine(S], regresston_Line(4]] colors" black") hee ee 4 ingort uy 86 m0 2a Plot the Mstopran of residuals 5 plt-hist(restduals, binseround(np-sqrt(502)), colors'skyblue", adgecslone'lack") 4 plt.titleCLstogran of mestovsls') 5 plt-xlabel("Restevals’) 6 ple.ylabel(" Frequency’) 7 ple-eriatsrve) =: ee . apie shot) S Histogram of Residuals : | ” tn 20 wo} |} residuals 1 Standard Deviation 3 std « np. sta(restauals) 5 print(*standard oeviation:", std) 6 print(*3 tines standare deviation 8 for 5 An restau is 3 Sate re printesy 22 print (hax Residual", nax(restduats)) +, asta) standard eviatson: 3.s815227610086604 ioe Reet

You might also like