Linear regression demo using TensorFlow

Files

  • gradientdescent.py: Linear regression with gradient descent implementation
  • generate.py: Generate points along a function with some noise

More examples to practice

Linear model

xs =  [-0.9278957724351676, -0.8824189449569181, -0.8140559396580026, -0.7130626111089969, -0.5768740785335565, -0.5513577587187031, -0.44519898238288735, -0.4272472135425033, -0.38784963474749184, -0.29947703769787243, -0.19627220104997728, -0.17596950694456165, -0.0723916702536346, -0.1159377001676742, -0.056436197838169624, -0.06669338316783463, 0.18748490440772114, 0.18099265508346468, 0.27975130390230485, 0.28106406138870954, 0.26383924236828066, 0.3786144422569561, 0.47178232850765167, 0.46705350890809816, 0.5481018128734858, 0.5836019922727367, 0.6380091317493796, 0.85184406639726, 0.8454219658618363, 0.8085475758205278]
ys =  [4.320156683726161, 3.9877049913162317, 3.912711566794872, 4.090707523565881, 3.4731105756842315, 3.7224913453216835, 3.486382597831084, 3.7415259505139877, 3.322888831360482, 3.0991915954971088, 3.3111983094271755, 3.0391723743212786, 3.1470788081450594, 2.9312366696875483, 3.2345327962978714, 2.7874547522018194, 2.8314428539039365, 2.6444813440226036, 2.462539360746174, 2.4201160906996892, 2.5146448266761325, 2.6280427070906964, 2.1509256092091, 2.640939123629154, 2.5129711691339547, 2.457021001130864, 2.3163047801496313, 1.7138175760387198, 1.8584202147540319, 1.7192318395074575]

Second degree polynomial

xs =  [-0.9483665594698729, -0.8672115501451058, -0.8735252788248331, -0.8088719021042359, -0.8314302395146844, -0.7658306163026405, -0.7448814564393204, -0.6583101072706791, -0.6402337536251926, -0.627080629625837, -0.5212930125861542, -0.5411272974101071, -0.4620954147816115, -0.4749776128049986, -0.4307946895490914, -0.37994384992563773, -0.2909908593144043, -0.3348982193951544, -0.22480927375309503, -0.17546131449805008, -0.16089868894498652, -0.09339313046478699, -0.07014601933483411, -0.09433239505775087, 0.009992047527420972, 0.04082589443020765, 0.02595778955736261, 0.06400841916081919, 0.1445124630530965, 0.19384459243411636, 0.21856020446959618, 0.2682942420230835, 0.246733986866081, 0.3490214380349636, 0.33420165769295923, 0.42461339590855796, 0.49317123169370425, 0.4706585195515338, 0.47938631299937884, 0.6098890693445648, 0.6319764187988992, 0.6483120843317152, 0.66450107074288, 0.699523260537854, 0.7935862856254415, 0.7616647827859189, 0.8327097537046246, 0.8884942202006161, 0.9089876296968886, 0.9843912859076669]
ys =  [2.5489635508792396, 2.2620836218349396, 2.3969266769732367, 2.226275758295137, 2.257513790667867, 1.952699990756468, 1.9446422827432002, 1.7432867988457619, 1.814381206695935, 1.699730625424567, 1.5904617581607168, 1.5093409922444287, 1.4555958048084268, 1.5203114367901502, 1.407346987231123, 1.3225422080231228, 1.1490371502886543, 1.3232521709133327, 1.0580818641650365, 1.082749404217386, 1.1047643010900923, 1.1220859530926903, 0.9814333964113798, 0.9690758659547926, 0.9940245207511582, 1.0744731543684136, 0.9131266368372292, 0.9717242109629536, 0.9148008950814933, 0.939994761112193, 0.9685834526497747, 0.9636919632085779, 1.1202096368587173, 1.0272909827609735, 1.1371310414271172, 1.1018018072904547, 1.2059137974694274, 1.241217331638907, 1.2687830983152641, 1.3654495972154004, 1.459945642382861, 1.415223354407581, 1.4185405905152202, 1.4692831611719908, 1.5953706565878982, 1.5724868924020947, 1.8020019428021905, 1.9024919782092602, 1.9499215651169188, 2.1346589255687154]

Third degree polynomial

xs =  [-0.8797718501431324, -0.9598922447811636, -0.8571179367280469, -0.8566272032216253, -0.7144915782817037, -0.7242592188037956, -0.6889610065123639, -0.6974916651046077, -0.5998400559742701, -0.5876214146311244, -0.5421036709298775, -0.5691230073640161, -0.46848679412155175, -0.5096233863969567, -0.3387972977547739, -0.28491571076733413, -0.3419285661866614, -0.21526328679947757, -0.23117759852635256, -0.2669613970530007, -0.09501596310046947, -0.10577772139258951, -0.009641330290791783, -0.13000691919484483, -0.021098242147471108, 0.08277962228804706, 0.03549060276693747, 0.021347479306133732, 0.1748749032550639, 0.22937302903197987, 0.17572546497800812, 0.18099050517919807, 0.32222937144529956, 0.23174077466733162, 0.26618196353130796, 0.38965208115261224, 0.4417742824436142, 0.5228203675424932, 0.5809962594675764, 0.4957207766214731, 0.6174558503295154, 0.5519306922332041, 0.616624509487695, 0.7657040281467827, 0.7168141758420892, 0.820137771938898, 0.8428249172860647, 0.8613303445949154, 0.8764484025965938, 0.8967597058318081]
ys =  [-2.0663454761456848, -3.538607695264483, -1.259642644010226, -1.3223698891109337, 0.33822467399516143, -0.07993397081155762, 1.00002810492808, 0.3062633685321571, 1.414747825386545, 1.45657904599625, 1.7828526300613439, 1.6353714138564281, 1.7013702257591063, 1.733715505471996, 2.3507830909358587, 1.9618621493255852, 1.8743061218403538, 2.334598462330675, 1.6684057894768984, 1.6611052010618046, 1.2146357556103027, 1.8123879045537024, 1.3578155316928244, 1.5298125628197576, 0.8083800851024041, 0.5563286347832441, 1.1301959968050126, 1.303851233849445, 1.138435162562236, 0.7157436073957401, 0.6870079089828849, 0.342292223547606, 0.5849417012340349, 1.0301190262379754, 0.26848470934625135, 0.3206920166894047, 0.4407919354471852, 0.8941344838665929, 1.3520886273185102, 0.7183453581032694, 1.838802383450461, 1.5484363722256584, 2.2815220126590807, 4.141479356511162, 2.664658939703056, 4.469250424271667, 5.188108679775746, 5.214034320782578, 6.105485250037409, 6.670329242017504]

Normalize first (second degree)

xs =  [27.07638132331846, 37.15882500098501, 23.33725057745685, 34.914765643546936, 35.55425092330577, 34.10835248195066, 32.611103466482355, 43.409685806178004, 42.68912408341307, 43.00970905720226, 39.43261748372252, 39.21901108896405, 46.70422963130088, 51.958764782851766, 39.1534937107409, 47.3501694316346, 42.367661215097, 53.59176009494428, 57.548626901225035, 49.60489589139829, 59.59919657528268, 52.62489700232561, 59.23398621627237, 54.12925614738894, 46.04798154068727, 53.80054761659324, 60.21524794586485, 63.98136621475523, 56.0423761539173, 63.11114792992985, 63.09576187489089, 57.25276416410821, 57.19809796054531, 69.4549302701604, 69.92050660779219, 70.22442677782013, 69.2130191977576, 58.23879319364101, 73.3206941115853, 61.02715070851837, 79.73127127608714, 67.40898219343353, 69.1650554698342, 78.18222048120373, 71.35431231587287, 69.94115485942129, 84.30279913284622, 78.00831228926319, 80.16997838007988, 79.69796537659106]
ys =  [1195.348419641808, 600.0746494810489, 1506.8402912224863, 725.5535851896658, 634.3214057559676, 793.031247391491, 855.3298560055871, 330.42962465560186, 323.7490558634524, 291.93059817243306, 455.18836427411816, 504.16449118915534, 162.9337350943748, 10.359144805289958, 505.33267645593077, 112.92368807331928, 310.98748157814737, 19.182410678549658, -81.37356260342702, 100.32128278267878, -107.76763087956638, -17.585679434915242, -151.78334005974347, -6.84035115568328, 210.68290716503125, 23.88106773223818, -82.05435196205386, -122.51427749885028, -38.23552769520738, -105.89017067424251, -146.94392595476256, -129.29550507361142, -83.45389067481406, -67.5535036262074, -51.93171720172148, -71.23653070952494, -57.959114794565764, -94.9269968474058, -80.09659632548713, -152.42405030883677, 157.670521782594, -167.71814704128445, -94.38601603838508, 110.52545391597332, -86.58352425634837, -77.57512270920681, 233.47016966247043, 61.15917267854534, 100.70871990418502, 76.67726982092444]