Data Analysis From Scratch With Python: Step By Step Guide



Download 2,79 Mb.
Pdf ko'rish
bet37/60
Sana30.05.2022
Hajmi2,79 Mb.
#620990
1   ...   33   34   35   36   37   38   39   40   ...   60
Bog'liq
Data Analysis From Scratch With Python Beginner Guide using Python, Pandas, NumPy, Scikit-Learn, IPython, TensorFlow and... (Peters Morgan) (z-lib.org)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()


X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
We first transformed the data into the same
range or scale to avoid skewing or heavy reliance on a certain variable. In our
dataset, the Estimated Salary is expressed in thousands while age is expressed in
a smaller scale. We have to make them in the same range so we can get a more
reasonable model.
Well, aside from Logistic Regression, there are other ways of performing
Classification tasks. Let’s discuss them next.
K-Nearest Neighbors
Notice that Logistic Regression seems to have a linear boundary between 0s and
1s. As a result, it misses a few of the data points that should have been on the
other side.
Thankfully, there are non-linear models that can capture more data points in a
more accurate manner. One of them is through the use of K-Nearest Neighbors.
It works by having a “new data point” and then counting how many neighbors
belong to either category. If more neighbors belong to category A than category
B, then the new point should belong to category A.
Therefore, the classification of a certain point is based on the majority of its
nearest neighbors (hence the name). This can often be accomplished by the
following code: 
from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p
= 2)
classifier.fit(X_train, y_train)
Again, instead of starting from scratch, we’re
importing “prebuilt code” that makes our task faster and easier. The behind the
scenes could be learned and studied. But for many purposes, the prebuilt ones
are good enough to make reasonably useful models.
Let’s look at an example of how to implement this using again the data set
‘Social_Network_Ads.csv’: 

Download 2,79 Mb.

Do'stlaringiz bilan baham:
1   ...   33   34   35   36   37   38   39   40   ...   60




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish