Question: import numpy as np import matplotlib.pyplot as plt import pandas as pd class LinearRegression: def _ _ init _ _ ( self , X ,
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
class LinearRegression:
def initselfXY: # x ve y ayrlp verilecek
onesnponesXshape
XnpappendonesXaxis
self.XX
self.YY
self.mXshape
self.nXshape
self.thetanprandom.randnXshape
def computeCostFunctionself:
hnpmatmulselfXself.theta
self.Jselfmnpsumhself.Y
return self.J
def performGradientDescentselfnumofiter,alpha:# iterasyon says
self.Costhistory
self.thetahistory
for x in rangenumofiter:
hnpmatmulselfXself.theta
Jself.computeCostFunction
self.Costhistory.appendJ
self.thetahistory.appendselftheta
temphself.Y
self.thetaself.thetaalphaselfmselfXTdottemp
return self.theta,self.Costhistory,self.thetahistory
def predictselfXtest,Ytest:
onesnponesXtest.shape
XtestnpappendonesXtest,axis
self.YprednpmatmulXtest,self.theta
self.errorpercentageabsselfYpredYtestYtest
return self.Ypred,self.errorpercentage
def predictUsingNormalEquationselfXtest,Ytest:
onesnponesXtest.shape
XtestnpappendonesXtest,axis
invnplinalg.invnpmatmulselfXTself.X
self.wnpmatmulnpmatmulinvself.XTself.Y
yprednpmatmulXtest,self.w
return ypred,absYtestypredYtest bu kodu bir rnekte Bu almada Pythonda Dorusal Regresyon Linear Regression sfrdan uygulayacaksnz
Veri Seti znitelikleri:
Kategori,
Sayfa toplam beenisi: irketin sayfasn beenen kii says
Tr: erik trBalant Fotoraf Durum, Video
Gnderi ay: Gnderinin yaynland ay Ocakubat Mart,..., Aralk
Gnderim saati: Gnderinin yaynland saat
Hafta ii gnderi: Gnderinin yaynland hafta ii Pazar Pazartesi, Cumartesi
cretli: irketin reklam iin Facebook'a deme yapmas durumunda evet hayr
Modellemek iin:
Modellemeye alabileceimiz birok olaszellik var ancak biz Total Interactionse
odaklanacazzellik alanmz unlar ierecektir: CategoryPage total likesPost month
Post hourPost weekday ve Paidn ilemeyi nlemek iin "Type" seeneini brakyoruz
Veri Seti: Facebook Posts Metrics
Takip Edilmesi Gereken Admlar:
Verinin indirilmesi
Verinin okunmas
Verileri Blme X ve Y Xtrain, XTest ve ytrain, ytest
a Veri kmesini X ve Y'ye bln
b Salanan yzdesel blmeyi kullanarak X ve Y'yi eitim ve test setlerine ayrn
varsaylan eitim ve testtir
Modelin eitimi ve test edilmesi
a traintestsplitesini ararak eitim ve test setini aln
b Bir arlk theta vektrn tanmlayn
c Yukardaki bilgileri kullanarak Gradyan niini Gradient Descent uygulayn
d Eitim ve test verileri iin Toplam Kare HataySum Squared Error kaydedin
e Arlk matrisini, eitim hatalarn ve test hatalarn dndrn
f Eitim ve test hatalarnizin ve grafik zerinde yorum yapn bu devi uygula
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
