Xitoyning Yaim qiymati va yillar kesimidagi bog’liqligini polinominal usulda bosqichma bosqich aks ettiring


Download 88.69 Kb.
Sana18.11.2023
Hajmi88.69 Kb.
#1786064
Bog'liq
8-topshiriq 11.11

Seminar topshiriq


Xitoyning YaIM qiymati va yillar kesimidagi bog’liqligini polinominal usulda bosqichma bosqich aks ettiring.

import numpy as np


import matplotlib.pyplot as plt

# Given data


years = [1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014]
values = [59184116488.9977, 49557050182.9631, 46685178504.3274, 50097303271.0232, 59062254890.1871, 69709153115.3147, 75879434776.1831, 72057028559.6741, 69993497892.3132, 78718820477.9257, 91506211306.3745, 98562023844.1813, 112159813640.376, 136769878359.668, 142254742077.706, 161162492226.686, 151627687364.405, 172349014326.931, 148382111520.192, 176856525405.729, 189649992463.987, 194369049090.197, 203549627211.606, 228950200773.115, 258082147252.256, 307479585852.339, 298805792971.544, 271349773463.863, 310722213686.031, 345957485871.286, 358973230048.399, 381454703832.753, 424934065934.066, 442874596387.119, 562261129868.774, 732032045217.766, 860844098049.121, 958159424835.341, 1025276902078.73, 1089447108705.89, 1205260678391.96, 1332234719889.82, 1461906487857.92, 1649928718134.59, 1941745602165.09, 2268598904116.28, 2729784031906.09, 3523094314820.92, 4558431073438.22, 5059419738267.41, 6039658508485.59, 7492432097810.11, 8461623162714.07, 9490602600148.49, 10354831729340.4]

# Perform polynomial regression of degree 2


coefficients = np.polyfit(years, values, 2)
polynomial = np.poly1d(coefficients)

# Generate x values for the regression line


x_regression = np.linspace(min(years), max(years), 100)

# Generate y values for the regression line


y_regression = polynomial(x_regression)

# Plot the original data points


plt.scatter(years, values, color='blue', label='Data Points')

# Plot the regression line


plt.plot(x_regression, y_regression, color='red', label='Regression Line')

# Label the axes and add a legend


plt.xlabel('Year')
plt.ylabel('Value')
plt.legend()

# Show the plot


plt.show()

import numpy as np


import matplotlib.pyplot as plt

# Given data


years = [1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014]
values = [59184116488.9977, 49557050182.9631, 46685178504.3274, 50097303271.0232, 59062254890.1871, 69709153115.3147, 75879434776.1831, 72057028559.6741, 69993497892.3132, 78718820477.9257, 91506211306.3745, 98562023844.1813, 112159813640.376, 136769878359.668, 142254742077.706, 161162492226.686, 151627687364.405, 172349014326.931, 148382111520.192, 176856525405.729, 189649992463.987, 194369049090.197, 203549627211.606, 228950200773.115, 258082147252.256, 307479585852.339, 298805792971.544, 271349773463.863, 310722213686.031, 345957485871.286, 358973230048.399, 381454703832.753, 424934065934.066, 442874596387.119, 562261129868.774, 732032045217.766, 860844098049.121, 958159424835.34, 1025276902078.73, 1089447108705.89, 1205260678391.96, 1332234719889.82, 1461906487857.92, 1649928718134.59, 1941745602165.09, 2268598904116.28, 2729784031906.09, 3523094314820.9, 4558431073438.2, 5059419738267.41, 6039658508485.59, 7492432097810.11, 8461623162714.07, 9490602600148.49, 10354831729340.4]

# Convert data to numpy arrays


x = np.array(years)
y = np.array(values)

# Perform polynomial regression


degree = 3 # Choose the degree of the polynomial
coefficients = np.polyfit(x, y, degree)
polynomial = np.poly1d(coefficients)

# Generate predicted values using the polynomial


x_pred = np.linspace(min(x), max(x), 100)
y_pred = polynomial(x_pred)

# Plot the original data and the polynomial regression curve


plt.scatter(x, y, label='Data')
plt.plot(x_pred, y_pred, color='red', label='Polynomial Regression')
plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Polynomial Regression')
plt.legend()
plt.show()



419-guruh talabasi HAKIMOV MUZAFFAR
Download 88.69 Kb.

Do'stlaringiz bilan baham:




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