Bajardi: Ziyodullayeva Dilnoza


Download 379.66 Kb.
Sana06.11.2023
Hajmi379.66 Kb.
#1752835
Bog'liq
Ziyodullayeva Dilnoza (3)


O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI


MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI







1-Amaliy topshiriq.




Guruh: 715_21

Bajardi:Ziyodullayeva Dilnoza


Tekshirdi: Ochilov Mannon
Toshkent 2023

21-variant

21

Eski yuk mashinasining narxini bashorat qilish

20

numpy

2,3,6

1,3,6

https://colab.research.google.com/drive/1E1a6NJBO38SQp5OYZpvd3agmhUOeUby2#scrollTo=SM67CQhZ88_H


import numpy as np


import matplotlib.pyplot as plt

dataset = np.array([


[6.6, 3.2, 90],
[6.4, 4, 87],
[6.5, 2.5, 85],
[6, 4, 83],
[5.9, 3, 82],
[5.8, 2.5, 80],
[5.7, 3, 78],
[5.5, 3, 77],
[5.4, 2.5, 75],
[5.2, 2, 72],
[5, 4, 68],
[4.8, 3, 67.5],
[4, 3, 67],
[3.8, 4, 65],
[3.7, 3, 64],
[3.5, 4, 63],
[3.3, 3, 61],
[3.2, 2.5, 59],
[3, 3, 57],
[2.8, 3, 55]
])

#Datasetdagi 2 ta xususiyatni o’zaro bog’laymiz( mashina holati va mashina narxini)


x= dataset[:,0]
y = dataset[:,-1]

print(x)
Grafik tasvirlash uchun plt dan foydalanamiz.


plt.figure(figsize=(6,3))
plt.scatter(x,y,marker="s", color="r")
plt.xlabel("mashina holati")
plt.ylabel("mashina narxi")
plt.title("Datasetdagi mashina narxining mashina holatiga bog'liqligi")
plt.grid()
plt.show()

Polinomial darajasi 2 bo’lgan hol uchun:
p = np.polyfit(x,y,2)
reg_model = np.poly1d(p)
yNew = reg_model(x)

plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plt.scatter(x,y,marker="s", color="r", label = "original data")
plt.xlabel("mashina holati")
plt.ylabel("mashina narxi")
plt.title("Dataset")
plt.grid()
plt.subplot(1,2,2)
plt.plot(x,yNew, color = "b", label = "reg model")
plt.xlabel("mashina holati")
plt.ylabel("mashina narxi")
plt.title("Regression model")
plt.grid()
plt.legend()
plt.show()


Polinomial darajasi 3 bo’lgan hol uchun:
p = np.polyfit(x,y,3)
reg_model = np.poly1d(p)
yNew = reg_model(x)

Polinomial darajasi 6 bo’lgan hol uchun:
p = np.polyfit(x,y,6)
reg_model = np.poly1d(p)
yNew = reg_model(x)

SKLEARN
Sklearn kutubxonasi bizga bir necha xil polinomial darajalarni bitta funksiyada chiqarishga yordam beradi


from sklearn.preprocessing import PolynomialFeatures

import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import numpy

x = dataset[:,0]
y = dataset[:,2]

X=x.reshape(-1,1)
#degree=1 , polinomial darajasi 1 bo’lgan hol uchun
poly_reg = PolynomialFeatures(degree=1)

X_poly = poly_reg.fit_transform(X)

pol_reg = LinearRegression()

pol_reg.fit(X_poly, y)

plt.figure(figsize=(6,3))
plt.scatter(X, y, color='red')
plt.xlabel("mashina holati")
plt.ylabel("mashina narxi")
plt.title("Regression model")
plt.plot(X, pol_reg.predict(poly_reg.fit_transform(X)), color='blue')
plt.grid()
plt.show()

from sklearn.preprocessing import PolynomialFeatures

import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import numpy

x = dataset[:,0]
y = dataset[:,2]

X=x.reshape(-1,1)
#degree=3 , polinomial darajasi 3 bo’lgan hol uchun
poly_reg = PolynomialFeatures(degree=3)

X_poly = poly_reg.fit_transform(X)

pol_reg = LinearRegression()

pol_reg.fit(X_poly, y)

plt.figure(figsize=(6,3))
plt.scatter(X, y, color='red')
plt.xlabel("mashina holati")
plt.ylabel("mashina narxi")
plt.title("Regression model")
plt.plot(X, pol_reg.predict(poly_reg.fit_transform(X)), color='blue')
plt.grid()
plt.show()

from sklearn.preprocessing import PolynomialFeatures
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import numpy

x = dataset[:,0]
y = dataset[:,2]

X=x.reshape(-1,1)
#degree=6 , polinomial darajasi 6 bo’lgan hol uchun
poly_reg = PolynomialFeatures(degree=6)

X_poly = poly_reg.fit_transform(X)

pol_reg = LinearRegression()

pol_reg.fit(X_poly, y)

plt.figure(figsize=(6,3))
plt.scatter(X, y, color='red')
plt.xlabel("mashina holati")
plt.ylabel("mashina narxi")
plt.title("Regression model")
plt.plot(X, pol_reg.predict(poly_reg.fit_transform(X)), color='blue')
plt.grid()
plt.show()



https://colab.research.google.com/drive/1E1a6NJBO38SQp5OYZpvd3agmhUOeUby2#scrollTo=SM67CQhZ88_H
Download 379.66 Kb.

Do'stlaringiz bilan baham:




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