Data Analysis From Scratch With Python: Step By Step Guide



Download 2,79 Mb.
Pdf ko'rish
bet26/60
Sana30.05.2022
Hajmi2,79 Mb.
#620990
1   ...   22   23   24   25   26   27   28   29   ...   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)

random_state = 0)
# Fitting Simple Linear Regression to the Training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# Predicting the Test set results
y_pred = regressor.predict(X_test)


# Visualising the Training set results
plt.scatter(X_train, y_train, color = 'red')
plt.plot(X_train, regressor.predict(X_train), color = 'blue')
plt.title('Salary vs Experience (Training set)')
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.show()
# Visualising the Test set results
plt.scatter(X_test, y_test, color = 'red')
plt.plot(X_train, regressor.predict(X_train), color = 'blue')
plt.title('Salary vs Experience (Test set)')
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.show()
The overall goal here is to create a model that will predict Salary
based on Years of Experience. First, we create a model using the Training Set
(70% of the dataset). It will then fit a line that is close as possible with most of
the data points.
After the line is created, we then apply that same line to the Test Set (the
remaining 30% or 1/3 of the dataset).


Notice that the line performed well both on the Training Set and the Test Set. As
a result, there’s a good chance that the line or our model will also perform well
on new data.
Let’s have a recap of what happened. First, we imported the necessary libraries
(pandas for processing data, matplotlib for data visualization). Next, we
imported the dataset and assigned X (the independent variable) to Years of
Experience and y (the target) to Salary. We then split the dataset into Training
Set (⅔) and Test Set (⅓).
Then, we apply the Linear Regression model and fitted a line (with the help of
scikit-learn, which is a free software machine learning library for the Python
programming language). This is accomplished through the following lines of
code: 

Download 2,79 Mb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   ...   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