In: Computer Science
USING MATLAB:
Using the data from table below fit a fourth-order polynomial to the data, but use a label for the year starting at 1 instead of 1872. Plot the data and the fourth-order polynomial estimate you found, with appropriate labels. What values of coefficients did your program find? What is the LMS loss function value for your model on the data?
Year Built | SalePrice |
1885 | 122500 |
1890 | 240000 |
1900 | 150000 |
1910 | 125500 |
1912 | 159900 |
1915 | 149500 |
1920 | 100000 |
1921 | 140000 |
1922 | 140750 |
1923 | 109500 |
1925 | 87000 |
1928 | 105900 |
1929 | 130000 |
1930 | 138400 |
1936 | 123900 |
1938 | 119000 |
1939 | 134000 |
1940 | 119000 |
1940 | 244400 |
1942 | 132000 |
1945 | 80000 |
1948 | 129000 |
1950 | 128500 |
1951 | 141000 |
1957 | 149700 |
1958 | 172000 |
1959 | 128950 |
1960 | 215000 |
1961 | 105000 |
1962 | 84900 |
1963 | 143000 |
1964 | 180500 |
1966 | 142250 |
1967 | 178900 |
1968 | 193000 |
1970 | 149000 |
1971 | 149900 |
1972 | 197500 |
1974 | 170000 |
1975 | 120000 |
1976 | 130500 |
1977 | 190000 |
1978 | 206000 |
1980 | 155000 |
1985 | 212000 |
1988 | 164000 |
1990 | 171500 |
1992 | 191500 |
1993 | 175900 |
1994 | 325000 |
1995 | 236500 |
1996 | 260400 |
1997 | 189900 |
1998 | 221000 |
1999 | 333168 |
2000 | 216000 |
2001 | 222500 |
2002 | 320000 |
2003 | 538000 |
2004 | 192000 |
2005 | 220000 |
2006 | 205000 |
2007 | 306000 |
2008 | 262500 |
2009 | 376162 |
2010 | 394432 |
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
clear all
clc
M=load('aa.txt');
n=size(M,1);
x=[13, 18, 28, 38, 40, 43, 48, 49, 50, 51, 53, 56, 57, 58, 64, 66,
67, 68, 68, 70, 73, 76, 78, 79, 85, 86, 87, 88, 89, 90, 91, 92, 94,
95, 96, 98, 99, 100, 102, 103, 104, 105, 106, 108, 113, 116, 118,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
133, 134, 135, 136, 137, 138]+1;
y=[122500, 240000, 150000, 125500, 159900, 149500, 100000, 140000,
140750, 109500, 87000, 105900, 130000, 138400, 123900, 119000,
134000, 119000, 244400, 132000, 80000, 129000, 128500, 141000,
149700, 172000, 128950, 215000, 105000, 84900, 143000, 180500,
142250, 178900, 193000, 149000, 149900, 197500, 170000, 120000,
130500, 190000, 206000, 155000, 212000, 164000, 171500, 191500,
175900, 325000, 236500, 260400, 189900, 221000, 333168, 216000,
222500, 320000, 538000, 192000, 220000, 205000, 306000, 262500,
376162, 394432];
C=polyfit(x,y,4);
disp('Coefficients of 4th order polynomial with 1872 as year
1');
disp(C);
xx=1:1:140;
yy=polyval(C,xx);
plot(x,y,'o',xx,yy);
xlabel('Year starting 1872 as 1');
ylabel('Sale Price');
disp('LMS is');
sum((y-polyval(C,x)).^2)
Kindly revert for any queries
Thanks.