Challenge

Independent Research Project

MACHINE LEARNING USING LINEAR REGRESSION ON BOSTON HOUSING DATASET:

independent research project for skill_lync by :nilesh gupta

MACHINE LEARNING:

Machine learning is an application of artificial intelligence (AI) that provides systems the ability to automatically learn and improve from experience without being explicitly programmed. Machine learning focuses on the development of computer programs that can access data and use it learn for themselves.

LINEAR REGRESSION:

Regression is a method of modelling a target value based on independent predictors. This method is mostly used for forecasting and finding out cause and effect relationship between variables.

linear regression is a type of regression analysis where the number of independent variables is one and there is a linear relationship between the independent(x) and dependent(y) variable.

PROCESS :

1.GOVERNING EQUATION: if x is independent variable. y is independent variable.

then relationship :

y= ax+b

here a and b are unknown

2.COST FUNCTION: The cost function helps us to figure out the best possible values for a and b which would provide the best fit line for the data points.

We choose the above function to minimize. The difference between the predicted values and ground truth measures the error difference. We square the error difference and sum over all data points and divide that value by the total number of data points. This provides the average squared error over all the data points.

Therefore, this cost function is also known as the Mean Squared Error(MSE) function. Now, using this MSE function we are going to change the values of a and b such that the MSE value settles at the minima.

Gradient Descent:

The next important concept needed to understand linear regression is gradient descent. Gradient descent is a method of updating a and b to reduce the cost function(MSE).

The idea is that we start with some values for a and b and then we change these values iteratively to reduce the cost. Gradient descent helps us on how to change the values.

Code

1.IMPORTING THE LIBRARY:

import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from sklearn.datasets import load_boston
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler

1.I import pandas, numpy, matplotlib, sklearn library to obtain the objective.

2.numpy is use for faster operations .

3.pandas use to store dataset into pandas array which have various predefined operations.

4.matplotlib operations use to create various plot.

5.the scikit learn library is built by google which i use to import the linear regression model for pre installed dataset of BOSTON HOUSING.

2.Data pre processing

"""data pre processing"""
#load data
boston=load_boston()
#for description
print(boston.DESCR)
#TOSTORE DATA IN PAndas
features=pd.DataFrame(boston.data,columns=boston.feature_names)
#to print features
print(features)

OUTPUT:

EXPLANATION:

I use pandas library to read the train and test files. retrieve the independent(x) and dependent(y) variables so that i could feed them into our linear regression model.

#to create target label
target=pd.DataFrame(boston.target,columns=['target'])
print(target)
#to concadinate dataframe
df=pd.concat([features,target],axis=1)
print(df)

output:

3.DATA VISUALIZATION;

"""to visualise data"""
df.describe()
#it gives output in terms of mean,std daviation,count,%change in one feature effect other

OUTPUT:

3.Data correlation:

"""to corelate data"""
corr=df.corr('pearson')
#perason is corellation method
#to take absolute value of corr coeff
corrs=[abs(corr[attr]['target']) for attr in list(features)]
#to make list of person coeff  and fetures
l=list(zip(corrs,list(features)))
#to sort the least of coeffs in descending order
l.sort(key=lambda x: x[0],reverse=True)
#to unzip
corrs,labels= list(zip((*l)))
"""plotting correlation values"""
index=np.arange(len(labels))
plt.figure(figsize=(15,5))
plt.bar(index,corrs,width=0.5)
plt.xlabel('attributes')
plt.ylabel('corr with target')
plt.xticks(index,labels)
plt.show()

OUTPUT:

EXPLANATION:

I use Sk learn library to correlate the features of given dataset with target label so that i found best possible independent feature on which target relies most.

"""to normalize data"""
X=df['LSTAT'].values
Y=df['target'].values
x_scaler=MinMaxScaler()
X=x_scaler.fit_transform(X.reshape(-1,1))
X=X[:,-1]
y_scaler=MinMaxScaler()
Y=y_scaler.fit_transform(Y.reshape(-1,1))
Y=Y[:,-1]

EXPLANATION:

data normalized to change its value in between 0 to 1 so that the operations are easier.

4.SPLITTING DATA

I use TRAIN_TEST_SPLIT to split data into training data and testing data.

xtrain,xtest,ytrain,ytest=train_test_split(X,Y,test_size=0.2)
#update function format 
def update(m,x,c,t,learning_rate):
    grad_m=sum(2*((m*x+c)-t)*x)
    grad_c=sum(2*((m*x+c)-t))
    m=m-grad_m*learning_rate
    c=c-grad_c*learning_rate
    return m,c
#error function format
def error(m,x,c,t):
    N=x.size
    e=sum(((m * x + c)-t)**2)
    return e*1/(2*N)
#grasdient descent function
def gradient_descent(init_m,init_c,x,t,learning_rate,iterations,error_threshold):
    m=init_m
    c=init_c
    error_values=list()
    mc_values=list()
    for i in range (iterations):
         e=error(m,x,c,t)
         if e<error_threshold:
             print("error less than threshold stoping gradient descent")
             break
         error_values.append(e)
         m,c=update(m,x,c,t,learning_rate)
         mc_values.append((m,c))
    return m,c,error_values,mc_values
-0.7653519307207601 0.619618983375355 [0.07004381264857937, 0.06162317000040183, 0.05861285925445261, 0.05583925947719905, 0.05322214572567382, 0.05075182139631075, 0.04842004138998519, 0.04621903549837916, 0.044141469464276085, 0.0421804203627776, 0.040329353530069625, 0.03858210078839509, 0.03693283989227554, 0.035376075127458384, 0.03390661899794096, 0.03251957494004833, 0.031210321005963826, 0.02997449446234268, 0.02880797725268718, 0.02770688227504167, 0.02666754042927979, 0.025686488390824862, 0.02476045707006048, 0.0238863607189768, 0.02306128664875301, 0.022282485524012335, 0.021547362201408335, 0.02085346708201402, 0.020198487948698485, 0.019580242261290733, 0.018996669883857273, 0.01844582621985811, 0.01792587573230682, 0.017435085827341594, 0.016971821080826687, 0.0165345377887452, 0.016121778823224738, 0.01573216877705403, 0.015364409380511989, 0.015017275175236069, 0.01468960943071512, 0.014380320289798715, 0.014088377130379809, 0.01381280713112614, 0.013552692029817313, 0.01330716506348523, 0.013075408080161588, 0.012856648812608834, 0.012650158304948927, 0.01245524848361595, 0.012271269864537597, 0.012097609388905889, 0.011933688380325084, 0.01177896061652958, 0.011632910509246681, 0.011495051386138403, 0.0113649238690982, 0.011242094343497998, 0.011126153513285187, 0.011016715037114683, 0.010913414240971163, 0.010815906902991963, 0.010723868106441171, 0.010636991157012752, 0.010554986560855037, 0.010477581059911107, 0.010404516721360408, 0.010335550078127647, 0.010270451317594905, 0.01020900351581348, 0.010151001914663603, 0.010096253239553715, 0.01004457505538527, 0.009995795158637289, 0.009949751003544944, 0.009906289160459854, 0.009865264804587425, 0.009826541233397572, 0.009789989411100626, 0.00975548753867062, 0.00972292064798302, 0.009692180218714732, 0.009663163816729565, 0.009635774752744254, 0.00960992176013772, 0.009585518690829731, 0.009562484228215944, 0.00954074161620226, 0.0095202184034361, 0.009500846201881831, 0.009482560458936255, 0.009465300242324587, 0.009449008037060183, 0.009433629553791406, 0.009419113547897198, 0.009405411648728218, 0.009392478198424786, 0.009380270099774504, 0.009368746672602435, 0.0093578695182155, 0.009347602391449262, 0.009337911079890744, 0.009328763289874826, 0.009320128538874399, 0.009311978053925625, 0.009304284675749798, 0.009297022768252514, 0.009290168133098207, 0.009283697929075919, 0.009277590595987024, 0.009271825782801824, 0.009266384279845195, 0.009261247954785628, 0.009256399692214068, 0.009251823336611537, 0.00924750363851522, 0.00924342620370378, 0.0092395774452325, 0.009235944538158508, 0.009232515376805098, 0.009229278534422895, 0.009226223225113312, 0.009223339267887388, 0.009220617052740515, 0.009218047508629658, 0.009215622073246535, 0.009213332664486129, 0.009211171653515196, 0.009209131839351242, 0.009207206424867291, 0.009205388994142211, 0.009203673491081435, 0.009202054199236689, 0.009200525722757444, 0.009199082968410726, 0.009197721128609306, 0.009196435665391722, 0.009195222295300723, 0.00919407697510984, 0.00919299588835044, 0.00919197543259435, 0.009191012207449747, 0.009190103003230305, 0.009189244790259786, 0.0091884347087764, 0.009187670059403494, 0.009186948294154599, 0.009186267007942957, 0.00918562393056717, 0.009185016919146461, 0.009184443950980031, 0.009183903116807014, 0.009183392614444319, 0.009182910742781408, 0.009182455896111757, 0.009182026558782298, 0.009181621300142934, 0.009181238769779268, 0.009180877693012651, 0.00918053686665283, 0.009180215154988437, 0.009179911486002695, 0.009179624847801122, 0.009179354285239737, 0.009179098896742234, 0.009178857831295777, 0.009178630285615212, 0.009178415501466287, 0.009178212763139165, 0.009178021395063383, 0.009177840759556787, 0.009177670254700569, 0.009177509312333609, 0.00917735739615912, 0.009177213999957693, 0.00917707864590044, 0.009176950882956683, 0.009176830285391077, 0.00917671645134501, 0.009176609001497393, 0.009176507577800787, 0.009176411842288268, 0.009176321475947184, 0.009176236177656269, 0.009176155663182119, 0.009176079664232093, 0.009176007927560343, 0.009175940214123837, 0.00917587629828599, 0.009175815967064557, 0.009175759019422164, 0.00917570526559624, 0.009175654526466744, 0.009175606632959308, 0.009175561425481822, 0.009175518753392625, 0.009175478474498578, 0.009175440454581173, 0.009175404566949397, 0.009175370692017435, 0.009175338716906265, 0.009175308535067513, 0.009175280045928406, 0.009175253154556605, 0.009175227771343927, 0.009175203811707701, 0.009175181195808938, 0.009175159848286301, 0.009175139698004951, 0.009175120677819578, 0.009175102724350534, 0.009175085777772788, 0.009175069781616472, 0.009175054682578706, 0.009175040430346075, 0.009175026977426875, 0.009175014278992885, 0.009175002292730064, 0.009174990978697404, 0.009174980299193971, 0.009174970218633251, 0.009174960703424443, 0.009174951721860766, 0.009174943244013566, 0.00917493524163272, 0.009174927688052458, 0.009174920558102536, 0.009174913828024335, 0.009174907475391701, 0.009174901479036183, 0.009174895818976576, 0.009174890476352258, 0.009174885433360395, 0.009174880673196587, 0.009174876179998856, 0.009174871938794868, 0.009174867935451943, 0.009174864156630042, 0.009174860589737259, 0.009174857222887878, 0.009174854044862806, 0.009174851045072147, 0.009174848213519885, 0.009174845540770643, 0.009174843017918249, 0.00917484063655593, 0.00917483838874848, 0.00917483626700567, 0.009174834264257388, 0.009174832373829987] [(0.8776771640396702, 0.09864607064017665), (0.8338448106824183, 0.12297486358724921), (0.7886629551539924, 0.13822715096157634), (0.7444619400941239, 0.15206251998376777), (0.7014825881152009, 0.1653890651436762), (0.6597216544033885, 0.17832300584523764), (0.6191481735675037, 0.19088743951421647), (0.5797288001007498, 0.2030942759222978), (0.541430754714974, 0.2149538513730692), (0.5042221457433296, 0.2264760633786875), (0.4680719834625881, 0.2376705109309841), (0.4329501590758575, 0.24854651797610086), (0.39882742019748274, 0.2591131429952064), (0.36567534655510636, 0.26937918676195466), (0.33346632632661244, 0.27935319969745565), (0.3021735331435953, 0.2890434889947072), (0.27177090374822066, 0.29845812553786394), (0.24223311628557487, 0.30760495062438514), (0.21353556921350578, 0.31649158249592857), (0.1856543608123992, 0.32512542268346045), (0.15856626927782577, 0.3335136621718701), (0.13224873337947837, 0.34166328738922425), (0.1066798336702907, 0.349581086025649), (0.08183827423008673, 0.35727365268668665), (0.057703364928555774, 0.364747394385835), (0.03425500419277969, 0.37200853588084465), (0.011473662264960324, 0.3790631248582186), (-0.010659635063597836, 0.3859170369702314), (-0.03216332225579707, 0.3925759807286646), (-0.05305530938251024, 0.3990455022593331), (-0.07335299703958735, 0.40533098992136307), (-0.09307329084052833, 0.4114376787950685), (-0.11223261549689323, 0.4173706550421643), (-0.130846928498177, 0.4231348601419477), (-0.14893173340254273, 0.4287350950069756), (-0.16650209274948258, 0.4341760239816668), (-0.18357264060516174, 0.43946217872715837), (-0.2001575947508938, 0.4445979619956523), (-0.21627076852489938, 0.4495876512973962), (-0.23192558232721025, 0.45443540246335196), (-0.24713507479730237, 0.4591452531065197), (-0.26191191367376615, 0.4637211259847997), (-0.27626840634505967, 0.46816683226819383), (-0.29021651010013205, 0.4724860747130668), (-0.30376784208745483, 0.4766824507461117), (-0.3169336889907556, 0.48075945546058807), (-0.3297250164295131, 0.48472048452732824), (-0.34215247809204313, 0.4885688370229362), (-0.3542264246087822, 0.4923077181775347), (-0.3659569121731587, 0.4959402420443495), (-0.37735371091723297, 0.49946943409335326), (-0.38842631304908115, 0.5028982337311304), (-0.3991839407587005, 0.5062294967490608), (-0.40963555389902145, 0.5094659977018623), (-0.4197898574484231, 0.5126104322184718), (-0.4296553087609681, 0.5156654192471907), (-0.43924012461039474, 0.5186335032369646), (-0.44855228803373454, 0.5215171562566129), (-0.4575995549802534, 0.5243187800537752), (-0.4663894607712555, 0.5270407080552876), (-0.4749293263761298, 0.5296852073106555), (-0.48322626450986605, 0.5322544803802429), (-0.49128718555711953, 0.5347506671697487), (-0.49911880332775765, 0.5371758467124991), (-0.506727640648683, 0.5395320389010411), (-0.5141200347965896, 0.5418212061694776), (-0.5213021427761775, 0.5440452551279473), (-0.5282799464482214, 0.546206038150609), (-0.5350592575117659, 0.5483053549184534), (-0.5416457223445938, 0.5503449539182291), (-0.5480448267060035, 0.552326533898728), (-0.5542619003058076, 0.5542517452856456), (-0.5603021212433617, 0.5561221915561937), (-0.566170520320319, 0.5579394305746108), (-0.5718719852307035, 0.5597049758896814), (-0.5774112646317902, 0.5614202979953463), (-0.5827929720991845, 0.5630868255554533), (-0.5880215899693945, 0.5647059465936675), (-0.5931014730730957, 0.5662790096495341), (-0.598036852362199, 0.567807324901655), (-0.6028318384337409, 0.5692921652589149), (-0.6074904249535339, 0.5707347674206664), (-0.6120164919824247, 0.5721363329067574), (-0.6164138092079343, 0.5734980290582565), (-0.6206860390839691, 0.574820990009713), (-0.6248367398812192, 0.5761063176337587), (-0.6288693686507842, 0.5773550824588402), (-0.6327872841034945, 0.5785683245608438), (-0.6365937494073269, 0.5797470544293588), (-0.6402919349052445, 0.5808922538092968), (-0.6438849207557232, 0.5820048765185717), (-0.6473756994981659, 0.5830858492425188), (-0.6507671785453393, 0.5841360723057163), (-0.6540621826049113, 0.5851564204218506), (-0.6572634560321038, 0.5861477434222508), (-0.6603736651154212, 0.5871108669637006), (-0.663395400297359, 0.588046593216113), (-0.666331178331941, 0.588955701530645), (-0.6691834443808828, 0.5898389490888071), (-0.6719545740501273, 0.5906970715331067), (-0.6746468753684476, 0.5915307835797531), (-0.6772625907097676, 0.5923407796139327), (-0.6798038986607978, 0.5931277342681517), (-0.6822729158355454, 0.5938923029841258), (-0.6846716986382069, 0.5946351225586876), (-0.6870022449759142, 0.5953568116741638), (-0.689266495922759, 0.596057971413666), (-0.6914663373364812, 0.5967391857617227), (-0.6936036014291699, 0.5974010220906707), (-0.6956800682932821, 0.5980440316332104), (-0.6976974673842536, 0.5986687499415184), (-0.6996574789609339, 0.5992756973333), (-0.7015617354850461, 0.5998653793251535), (-0.7034118229808382, 0.6004382870536071), (-0.7052092823560564, 0.6009948976841779), (-0.7069556106853429, 0.6015356748087957), (-0.7086522624571236, 0.6020610688319208), (-0.7103006507850296, 0.6025715173456792), (-0.7119021485848547, 0.6030674454943252), (-0.7134580897180359, 0.6035492663283376), (-0.7149697701026045, 0.6040173811484425), (-0.7164384487925349, 0.6044721798398504), (-0.7178653490263903, 0.6049140411969848), (-0.7192516592461384, 0.6053433332389743), (-0.720598534086985, 0.6057604135161697), (-0.7219070953390511, 0.6061656294079417), (-0.7231784328816934, 0.6065593184120075), (-0.7244136055912473, 0.6069418084255274), (-0.7256136422229479, 0.6073134180182047), (-0.7267795422677629, 0.6076744566976175), (-0.7279122767848528, 0.6080252251670023), (-0.7290127892103503, 0.608366015575705), (-0.7300819961431326, 0.6086971117625072), (-0.7311207881082419, 0.6090187894920309), (-0.7321300302985891, 0.6093313166844185), (-0.733110563295559, 0.6096349536384792), (-0.7340632037691167, 0.6099299532484869), (-0.7349887451579987, 0.6102165612148129), (-0.7358879583305554, 0.610495016248565), (-0.7367615922267944, 0.610765550270406), (-0.7376103744821606, 0.611028388603717), (-0.7384350120335721, 0.6112837501622657), (-0.7392361917082161, 0.6115318476325353), (-0.7400145807955963, 0.6117728876508687), (-0.7407708276033076, 0.6120070709755717), (-0.7415055619970005, 0.612234592654122), (-0.7422193959249863, 0.6124556421856201), (-0.7429129239279187, 0.6126704036786212), (-0.7435867236339774, 0.6128790560044753), (-0.7442413562399645, 0.613081772946307), (-0.7448773669787168, 0.6132787233437553), (-0.745495285573221, 0.6134700712335994), (-0.7460956266778118, 0.6136559759863804), (-0.7466788903068186, 0.6138365924391395), (-0.7472455622510193, 0.6140120710243788), (-0.7477961144822481, 0.6141825578953543), (-0.7483310055464927, 0.6143481950478042), (-0.7488506809458095, 0.6145091204382158), (-0.7493555735093758, 0.6146654680987258), (-0.7498461037539854, 0.6148173682487545), (-0.7503226802342909, 0.6149649474034633), (-0.7507856998830816, 0.6151083284791267), (-0.7512355483418827, 0.6152476308955077), (-0.7516726002821496, 0.6153829706753203), (-0.7520972197173259, 0.6155144605408631), (-0.7525097603060243, 0.6156422100079038), (-0.7529105656465829, 0.6157663254768931), (-0.7532999695632426, 0.6158869103215839), (-0.7536782963841842, 0.6160040649751296), (-0.7540458612116556, 0.6161178870137332), (-0.7544029701844159, 0.6162284712379171), (-0.7547499207327131, 0.6163359097514808), (-0.7550870018260085, 0.6164402920382125), (-0.7554144942136555, 0.616541705036419), (-0.7557326706587304, 0.616640233211335), (-0.7560417961652128, 0.6167359586254728), (-0.756342128198703, 0.616828961006971), (-0.7566339169008606, 0.6169193178159986), (-0.756917405297744, 0.6170071043092703), (-0.7571928295022222, 0.6170923936027268), (-0.7574604189106299, 0.6171752567324317), (-0.7577203963938276, 0.6172557627137361), (-0.7579729784828273, 0.6173339785987609), (-0.7582183755491375, 0.6174099695322433), (-0.7584567919799786, 0.6174837988057937), (-0.7586884263485132, 0.6175555279106121), (-0.7589134715792345, 0.6176252165887017), (-0.7591321151086504, 0.6176929228826277), (-0.759344539041396, 0.6177587031838595), (-0.7595509203019053, 0.6178226122797389), (-0.7597514307817694, 0.617884703399111), (-0.7599462374829017, 0.617945028256658), (-0.760135502656631, 0.6180036370959714), (-0.7603193839388384, 0.6180605787313991), (-0.7604980344812493, 0.6181159005887017), (-0.7606716030789912, 0.6181696487445534), (-0.7608402342945224, 0.618221867964918), (-0.7610040685780363, 0.6182726017423334), (-0.7611632423844394, 0.618321892332137), (-0.7613178882870032, 0.6183697807876581), (-0.7614681350877812, 0.6184163069944116), (-0.7616141079248873, 0.6184615097033173), (-0.76175592837672, 0.6185054265629752), (-0.7618937145632243, 0.6185480941510229), (-0.7620275812442711, 0.6185895480045993), (-0.7621576399152389, 0.618629822649944), (-0.7622839988998767, 0.6186689516311534), (-0.7624067634405252, 0.6187069675381187), (-0.7625260357857709, 0.6187439020336696), (-0.762641915275608, 0.618779785879946), (-0.7627544984241763, 0.618814648964019), (-0.7628638790001468, 0.6188485203227839), (-0.7629701481048201, 0.6188814281671435), (-0.7630733942480028, 0.6189133999055055), (-0.7631737034217262, 0.6189444621666104), (-0.7632711591718675, 0.6189746408217092), (-0.763365842667734, 0.6190039610061125), (-0.7634578327696674, 0.6190324471401244), (-0.7635472060947256, 0.6190601229493821), (-0.7636340370804956, 0.6190870114846162), (-0.7637183980470913, 0.61911313514085), (-0.763800359257388, 0.6191385156760513), (-0.763879988975543, 0.6191631742292545), (-0.7639573535238519, 0.619187131338167), (-0.7640325173379868, 0.6192104069562748), (-0.7641055430206648, 0.619233020469461), (-0.7641764913937875, 0.6192549907121526), (-0.7642454215490997, 0.6192763359830069), (-0.764312390897405, 0.6192970740601524), (-0.7643774552163831, 0.6193172222159958), (-0.7644406686970457, 0.619336797231608), (-0.7645020839888715, 0.6193558154107007), (-0.7645617522436569, 0.6193742925932056), (-0.7646197231581193, 0.6193922441684672), (-0.7646760450152896, 0.6194096850880599), (-0.7647307647247255, 0.6194266298782419), (-0.7647839278615816, 0.6194430926520529), (-0.7648355787045689, 0.619459087121069), (-0.7648857602728334, 0.6194746266068232), (-0.7649345143617863, 0.6194897240518998), (-0.764981881577914, 0.6195043920307153), (-0.7650279013725997, 0.61951864275999), (-0.7650726120749808, 0.6195324881089246), (-0.7651160509238732, 0.6195459396090846), (-0.7651582540987869, 0.6195590084640054), (-0.7651992567500588, 0.6195717055585235), (-0.7652390930281295, 0.6195840414678421), (-0.7652777961119863, 0.6195960264663392), (-0.7653153982367974, 0.6196076705361248), (-0.7653519307207601, 0.619618983375355)]

5.Training data:

#training data
init_m=0.9
init_c=0
learning_rate=0.001
iterations=250
error_threshold=0.001
m,c,error_values,mc_values=gradient_descent(init_m,init_c,xtrain,ytrain,learning_rate,iterations,error_threshold)
print(m,c,error_values,mc_values)
-0.7653519307207601 0.619618983375355 [0.07004381264857937, 0.06162317000040183, 0.05861285925445261, 0.05583925947719905, 0.05322214572567382, 0.05075182139631075, 0.04842004138998519, 0.04621903549837916, 0.044141469464276085, 0.0421804203627776, 0.040329353530069625, 0.03858210078839509, 0.03693283989227554, 0.035376075127458384, 0.03390661899794096, 0.03251957494004833, 0.031210321005963826, 0.02997449446234268, 0.02880797725268718, 0.02770688227504167, 0.02666754042927979, 0.025686488390824862, 0.02476045707006048, 0.0238863607189768, 0.02306128664875301, 0.022282485524012335, 0.021547362201408335, 0.02085346708201402, 0.020198487948698485, 0.019580242261290733, 0.018996669883857273, 0.01844582621985811, 0.01792587573230682, 0.017435085827341594, 0.016971821080826687, 0.0165345377887452, 0.016121778823224738, 0.01573216877705403, 0.015364409380511989, 0.015017275175236069, 0.01468960943071512, 0.014380320289798715, 0.014088377130379809, 0.01381280713112614, 0.013552692029817313, 0.01330716506348523, 0.013075408080161588, 0.012856648812608834, 0.012650158304948927, 0.01245524848361595, 0.012271269864537597, 0.012097609388905889, 0.011933688380325084, 0.01177896061652958, 0.011632910509246681, 0.011495051386138403, 0.0113649238690982, 0.011242094343497998, 0.011126153513285187, 0.011016715037114683, 0.010913414240971163, 0.010815906902991963, 0.010723868106441171, 0.010636991157012752, 0.010554986560855037, 0.010477581059911107, 0.010404516721360408, 0.010335550078127647, 0.010270451317594905, 0.01020900351581348, 0.010151001914663603, 0.010096253239553715, 0.01004457505538527, 0.009995795158637289, 0.009949751003544944, 0.009906289160459854, 0.009865264804587425, 0.009826541233397572, 0.009789989411100626, 0.00975548753867062, 0.00972292064798302, 0.009692180218714732, 0.009663163816729565, 0.009635774752744254, 0.00960992176013772, 0.009585518690829731, 0.009562484228215944, 0.00954074161620226, 0.0095202184034361, 0.009500846201881831, 0.009482560458936255, 0.009465300242324587, 0.009449008037060183, 0.009433629553791406, 0.009419113547897198, 0.009405411648728218, 0.009392478198424786, 0.009380270099774504, 0.009368746672602435, 0.0093578695182155, 0.009347602391449262, 0.009337911079890744, 0.009328763289874826, 0.009320128538874399, 0.009311978053925625, 0.009304284675749798, 0.009297022768252514, 0.009290168133098207, 0.009283697929075919, 0.009277590595987024, 0.009271825782801824, 0.009266384279845195, 0.009261247954785628, 0.009256399692214068, 0.009251823336611537, 0.00924750363851522, 0.00924342620370378, 0.0092395774452325, 0.009235944538158508, 0.009232515376805098, 0.009229278534422895, 0.009226223225113312, 0.009223339267887388, 0.009220617052740515, 0.009218047508629658, 0.009215622073246535, 0.009213332664486129, 0.009211171653515196, 0.009209131839351242, 0.009207206424867291, 0.009205388994142211, 0.009203673491081435, 0.009202054199236689, 0.009200525722757444, 0.009199082968410726, 0.009197721128609306, 0.009196435665391722, 0.009195222295300723, 0.00919407697510984, 0.00919299588835044, 0.00919197543259435, 0.009191012207449747, 0.009190103003230305, 0.009189244790259786, 0.0091884347087764, 0.009187670059403494, 0.009186948294154599, 0.009186267007942957, 0.00918562393056717, 0.009185016919146461, 0.009184443950980031, 0.009183903116807014, 0.009183392614444319, 0.009182910742781408, 0.009182455896111757, 0.009182026558782298, 0.009181621300142934, 0.009181238769779268, 0.009180877693012651, 0.00918053686665283, 0.009180215154988437, 0.009179911486002695, 0.009179624847801122, 0.009179354285239737, 0.009179098896742234, 0.009178857831295777, 0.009178630285615212, 0.009178415501466287, 0.009178212763139165, 0.009178021395063383, 0.009177840759556787, 0.009177670254700569, 0.009177509312333609, 0.00917735739615912, 0.009177213999957693, 0.00917707864590044, 0.009176950882956683, 0.009176830285391077, 0.00917671645134501, 0.009176609001497393, 0.009176507577800787, 0.009176411842288268, 0.009176321475947184, 0.009176236177656269, 0.009176155663182119, 0.009176079664232093, 0.009176007927560343, 0.009175940214123837, 0.00917587629828599, 0.009175815967064557, 0.009175759019422164, 0.00917570526559624, 0.009175654526466744, 0.009175606632959308, 0.009175561425481822, 0.009175518753392625, 0.009175478474498578, 0.009175440454581173, 0.009175404566949397, 0.009175370692017435, 0.009175338716906265, 0.009175308535067513, 0.009175280045928406, 0.009175253154556605, 0.009175227771343927, 0.009175203811707701, 0.009175181195808938, 0.009175159848286301, 0.009175139698004951, 0.009175120677819578, 0.009175102724350534, 0.009175085777772788, 0.009175069781616472, 0.009175054682578706, 0.009175040430346075, 0.009175026977426875, 0.009175014278992885, 0.009175002292730064, 0.009174990978697404, 0.009174980299193971, 0.009174970218633251, 0.009174960703424443, 0.009174951721860766, 0.009174943244013566, 0.00917493524163272, 0.009174927688052458, 0.009174920558102536, 0.009174913828024335, 0.009174907475391701, 0.009174901479036183, 0.009174895818976576, 0.009174890476352258, 0.009174885433360395, 0.009174880673196587, 0.009174876179998856, 0.009174871938794868, 0.009174867935451943, 0.009174864156630042, 0.009174860589737259, 0.009174857222887878, 0.009174854044862806, 0.009174851045072147, 0.009174848213519885, 0.009174845540770643, 0.009174843017918249, 0.00917484063655593, 0.00917483838874848, 0.00917483626700567, 0.009174834264257388, 0.009174832373829987] [(0.8776771640396702, 0.09864607064017665), (0.8338448106824183, 0.12297486358724921), (0.7886629551539924, 0.13822715096157634), (0.7444619400941239, 0.15206251998376777), (0.7014825881152009, 0.1653890651436762), (0.6597216544033885, 0.17832300584523764), (0.6191481735675037, 0.19088743951421647), (0.5797288001007498, 0.2030942759222978), (0.541430754714974, 0.2149538513730692), (0.5042221457433296, 0.2264760633786875), (0.4680719834625881, 0.2376705109309841), (0.4329501590758575, 0.24854651797610086), (0.39882742019748274, 0.2591131429952064), (0.36567534655510636, 0.26937918676195466), (0.33346632632661244, 0.27935319969745565), (0.3021735331435953, 0.2890434889947072), (0.27177090374822066, 0.29845812553786394), (0.24223311628557487, 0.30760495062438514), (0.21353556921350578, 0.31649158249592857), (0.1856543608123992, 0.32512542268346045), (0.15856626927782577, 0.3335136621718701), (0.13224873337947837, 0.34166328738922425), (0.1066798336702907, 0.349581086025649), (0.08183827423008673, 0.35727365268668665), (0.057703364928555774, 0.364747394385835), (0.03425500419277969, 0.37200853588084465), (0.011473662264960324, 0.3790631248582186), (-0.010659635063597836, 0.3859170369702314), (-0.03216332225579707, 0.3925759807286646), (-0.05305530938251024, 0.3990455022593331), (-0.07335299703958735, 0.40533098992136307), (-0.09307329084052833, 0.4114376787950685), (-0.11223261549689323, 0.4173706550421643), (-0.130846928498177, 0.4231348601419477), (-0.14893173340254273, 0.4287350950069756), (-0.16650209274948258, 0.4341760239816668), (-0.18357264060516174, 0.43946217872715837), (-0.2001575947508938, 0.4445979619956523), (-0.21627076852489938, 0.4495876512973962), (-0.23192558232721025, 0.45443540246335196), (-0.24713507479730237, 0.4591452531065197), (-0.26191191367376615, 0.4637211259847997), (-0.27626840634505967, 0.46816683226819383), (-0.29021651010013205, 0.4724860747130668), (-0.30376784208745483, 0.4766824507461117), (-0.3169336889907556, 0.48075945546058807), (-0.3297250164295131, 0.48472048452732824), (-0.34215247809204313, 0.4885688370229362), (-0.3542264246087822, 0.4923077181775347), (-0.3659569121731587, 0.4959402420443495), (-0.37735371091723297, 0.49946943409335326), (-0.38842631304908115, 0.5028982337311304), (-0.3991839407587005, 0.5062294967490608), (-0.40963555389902145, 0.5094659977018623), (-0.4197898574484231, 0.5126104322184718), (-0.4296553087609681, 0.5156654192471907), (-0.43924012461039474, 0.5186335032369646), (-0.44855228803373454, 0.5215171562566129), (-0.4575995549802534, 0.5243187800537752), (-0.4663894607712555, 0.5270407080552876), (-0.4749293263761298, 0.5296852073106555), (-0.48322626450986605, 0.5322544803802429), (-0.49128718555711953, 0.5347506671697487), (-0.49911880332775765, 0.5371758467124991), (-0.506727640648683, 0.5395320389010411), (-0.5141200347965896, 0.5418212061694776), (-0.5213021427761775, 0.5440452551279473), (-0.5282799464482214, 0.546206038150609), (-0.5350592575117659, 0.5483053549184534), (-0.5416457223445938, 0.5503449539182291), (-0.5480448267060035, 0.552326533898728), (-0.5542619003058076, 0.5542517452856456), (-0.5603021212433617, 0.5561221915561937), (-0.566170520320319, 0.5579394305746108), (-0.5718719852307035, 0.5597049758896814), (-0.5774112646317902, 0.5614202979953463), (-0.5827929720991845, 0.5630868255554533), (-0.5880215899693945, 0.5647059465936675), (-0.5931014730730957, 0.5662790096495341), (-0.598036852362199, 0.567807324901655), (-0.6028318384337409, 0.5692921652589149), (-0.6074904249535339, 0.5707347674206664), (-0.6120164919824247, 0.5721363329067574), (-0.6164138092079343, 0.5734980290582565), (-0.6206860390839691, 0.574820990009713), (-0.6248367398812192, 0.5761063176337587), (-0.6288693686507842, 0.5773550824588402), (-0.6327872841034945, 0.5785683245608438), (-0.6365937494073269, 0.5797470544293588), (-0.6402919349052445, 0.5808922538092968), (-0.6438849207557232, 0.5820048765185717), (-0.6473756994981659, 0.5830858492425188), (-0.6507671785453393, 0.5841360723057163), (-0.6540621826049113, 0.5851564204218506), (-0.6572634560321038, 0.5861477434222508), (-0.6603736651154212, 0.5871108669637006), (-0.663395400297359, 0.588046593216113), (-0.666331178331941, 0.588955701530645), (-0.6691834443808828, 0.5898389490888071), (-0.6719545740501273, 0.5906970715331067), (-0.6746468753684476, 0.5915307835797531), (-0.6772625907097676, 0.5923407796139327), (-0.6798038986607978, 0.5931277342681517), (-0.6822729158355454, 0.5938923029841258), (-0.6846716986382069, 0.5946351225586876), (-0.6870022449759142, 0.5953568116741638), (-0.689266495922759, 0.596057971413666), (-0.6914663373364812, 0.5967391857617227), (-0.6936036014291699, 0.5974010220906707), (-0.6956800682932821, 0.5980440316332104), (-0.6976974673842536, 0.5986687499415184), (-0.6996574789609339, 0.5992756973333), (-0.7015617354850461, 0.5998653793251535), (-0.7034118229808382, 0.6004382870536071), (-0.7052092823560564, 0.6009948976841779), (-0.7069556106853429, 0.6015356748087957), (-0.7086522624571236, 0.6020610688319208), (-0.7103006507850296, 0.6025715173456792), (-0.7119021485848547, 0.6030674454943252), (-0.7134580897180359, 0.6035492663283376), (-0.7149697701026045, 0.6040173811484425), (-0.7164384487925349, 0.6044721798398504), (-0.7178653490263903, 0.6049140411969848), (-0.7192516592461384, 0.6053433332389743), (-0.720598534086985, 0.6057604135161697), (-0.7219070953390511, 0.6061656294079417), (-0.7231784328816934, 0.6065593184120075), (-0.7244136055912473, 0.6069418084255274), (-0.7256136422229479, 0.6073134180182047), (-0.7267795422677629, 0.6076744566976175), (-0.7279122767848528, 0.6080252251670023), (-0.7290127892103503, 0.608366015575705), (-0.7300819961431326, 0.6086971117625072), (-0.7311207881082419, 0.6090187894920309), (-0.7321300302985891, 0.6093313166844185), (-0.733110563295559, 0.6096349536384792), (-0.7340632037691167, 0.6099299532484869), (-0.7349887451579987, 0.6102165612148129), (-0.7358879583305554, 0.610495016248565), (-0.7367615922267944, 0.610765550270406), (-0.7376103744821606, 0.611028388603717), (-0.7384350120335721, 0.6112837501622657), (-0.7392361917082161, 0.6115318476325353), (-0.7400145807955963, 0.6117728876508687), (-0.7407708276033076, 0.6120070709755717), (-0.7415055619970005, 0.612234592654122), (-0.7422193959249863, 0.6124556421856201), (-0.7429129239279187, 0.6126704036786212), (-0.7435867236339774, 0.6128790560044753), (-0.7442413562399645, 0.613081772946307), (-0.7448773669787168, 0.6132787233437553), (-0.745495285573221, 0.6134700712335994), (-0.7460956266778118, 0.6136559759863804), (-0.7466788903068186, 0.6138365924391395), (-0.7472455622510193, 0.6140120710243788), (-0.7477961144822481, 0.6141825578953543), (-0.7483310055464927, 0.6143481950478042), (-0.7488506809458095, 0.6145091204382158), (-0.7493555735093758, 0.6146654680987258), (-0.7498461037539854, 0.6148173682487545), (-0.7503226802342909, 0.6149649474034633), (-0.7507856998830816, 0.6151083284791267), (-0.7512355483418827, 0.6152476308955077), (-0.7516726002821496, 0.6153829706753203), (-0.7520972197173259, 0.6155144605408631), (-0.7525097603060243, 0.6156422100079038), (-0.7529105656465829, 0.6157663254768931), (-0.7532999695632426, 0.6158869103215839), (-0.7536782963841842, 0.6160040649751296), (-0.7540458612116556, 0.6161178870137332), (-0.7544029701844159, 0.6162284712379171), (-0.7547499207327131, 0.6163359097514808), (-0.7550870018260085, 0.6164402920382125), (-0.7554144942136555, 0.616541705036419), (-0.7557326706587304, 0.616640233211335), (-0.7560417961652128, 0.6167359586254728), (-0.756342128198703, 0.616828961006971), (-0.7566339169008606, 0.6169193178159986), (-0.756917405297744, 0.6170071043092703), (-0.7571928295022222, 0.6170923936027268), (-0.7574604189106299, 0.6171752567324317), (-0.7577203963938276, 0.6172557627137361), (-0.7579729784828273, 0.6173339785987609), (-0.7582183755491375, 0.6174099695322433), (-0.7584567919799786, 0.6174837988057937), (-0.7586884263485132, 0.6175555279106121), (-0.7589134715792345, 0.6176252165887017), (-0.7591321151086504, 0.6176929228826277), (-0.759344539041396, 0.6177587031838595), (-0.7595509203019053, 0.6178226122797389), (-0.7597514307817694, 0.617884703399111), (-0.7599462374829017, 0.617945028256658), (-0.760135502656631, 0.6180036370959714), (-0.7603193839388384, 0.6180605787313991), (-0.7604980344812493, 0.6181159005887017), (-0.7606716030789912, 0.6181696487445534), (-0.7608402342945224, 0.618221867964918), (-0.7610040685780363, 0.6182726017423334), (-0.7611632423844394, 0.618321892332137), (-0.7613178882870032, 0.6183697807876581), (-0.7614681350877812, 0.6184163069944116), (-0.7616141079248873, 0.6184615097033173), (-0.76175592837672, 0.6185054265629752), (-0.7618937145632243, 0.6185480941510229), (-0.7620275812442711, 0.6185895480045993), (-0.7621576399152389, 0.618629822649944), (-0.7622839988998767, 0.6186689516311534), (-0.7624067634405252, 0.6187069675381187), (-0.7625260357857709, 0.6187439020336696), (-0.762641915275608, 0.618779785879946), (-0.7627544984241763, 0.618814648964019), (-0.7628638790001468, 0.6188485203227839), (-0.7629701481048201, 0.6188814281671435), (-0.7630733942480028, 0.6189133999055055), (-0.7631737034217262, 0.6189444621666104), (-0.7632711591718675, 0.6189746408217092), (-0.763365842667734, 0.6190039610061125), (-0.7634578327696674, 0.6190324471401244), (-0.7635472060947256, 0.6190601229493821), (-0.7636340370804956, 0.6190870114846162), (-0.7637183980470913, 0.61911313514085), (-0.763800359257388, 0.6191385156760513), (-0.763879988975543, 0.6191631742292545), (-0.7639573535238519, 0.619187131338167), (-0.7640325173379868, 0.6192104069562748), (-0.7641055430206648, 0.619233020469461), (-0.7641764913937875, 0.6192549907121526), (-0.7642454215490997, 0.6192763359830069), (-0.764312390897405, 0.6192970740601524), (-0.7643774552163831, 0.6193172222159958), (-0.7644406686970457, 0.619336797231608), (-0.7645020839888715, 0.6193558154107007), (-0.7645617522436569, 0.6193742925932056), (-0.7646197231581193, 0.6193922441684672), (-0.7646760450152896, 0.6194096850880599), (-0.7647307647247255, 0.6194266298782419), (-0.7647839278615816, 0.6194430926520529), (-0.7648355787045689, 0.619459087121069), (-0.7648857602728334, 0.6194746266068232), (-0.7649345143617863, 0.6194897240518998), (-0.764981881577914, 0.6195043920307153), (-0.7650279013725997, 0.61951864275999), (-0.7650726120749808, 0.6195324881089246), (-0.7651160509238732, 0.6195459396090846), (-0.7651582540987869, 0.6195590084640054), (-0.7651992567500588, 0.6195717055585235), (-0.7652390930281295, 0.6195840414678421), (-0.7652777961119863, 0.6195960264663392), (-0.7653153982367974, 0.6196076705361248), (-0.7653519307207601, 0.619618983375355)]
#data visulaization
#ploting regression line with data
plt.scatter(xtrain,ytrain,color='b')
plt.plot(xtrain,(m*xtrain+c),color='r')
plt.grid()
plt.show()

OUTPUT:

#ploting error values
plt.plot((np.arange(len(error_values))),error_values)
plt.ylabel('error')
plt.xlabel('iterations')
plt.show()

OUTPUT:

6.Prediction

#prediction
predicted= m*(xtest) + c
mean_squared_error(ytest,predicted)
p=pd.DataFrame(list(zip(xtest,ytest,predicted)),columns=['x','target_y','predicted'])
p.head()

OUTPUT:

#plotting test data
plt.scatter(xtest,ytest,color='b')
plt.plot(xtest,predicted,color='r')
plt.show()

OUTPUT:

7.Revert normalization

to convert 0 to 1 values into actual values.

#revert normalization
predicted=predicted.reshape(-1,1)
xtest=xtest.reshape(-1,1)
ytest=ytest.reshape(-1,1)

xtest_scaled=x_scaler.inverse_transform(xtest)
ytest_scaled=y_scaler.inverse_transform(ytest)
predicted_scaled=y_scaler.inverse_transform(predicted)

#to remove extra dimension

xtest_scaled=xtest_scaled[:,-1]
ytest_scaled=ytest_scaled[:,-1]
predicted_scdaled=predicted_scaled[:,-1]

p=pd.DataFrame(list(zip(xtest_scaled,ytest_scaled,predicted_scaled)),columns=['x','target_y','predicted_y'])
p=p.round(decimals=2)
p.head()

OUTPUT:

CONCLUSION: HENCE I FOUND OUT LINEAR REGRESSION IS BASIC LEARNING METHOD FOR EVERY PERSON WHICH START HIS CAREER IN MACHINE LEARNING.

THANK YOU

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.