Prac 2
Prac 2
df=pd.read_csv("D:temperatures.csv")
df.describe()
YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP
count 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.00
mean 1959.000000 23.687436 25.597863 29.085983 31.975812 33.565299 32.774274 31.035897 30.507692 30.486752 29.76
std 33.919021 0.834588 1.150757 1.068451 0.889478 0.724905 0.633132 0.468818 0.476312 0.544295 0.70
min 1901.000000 22.000000 22.830000 26.680000 30.010000 31.930000 31.100000 29.760000 29.310000 29.070000 27.90
25% 1930.000000 23.100000 24.780000 28.370000 31.460000 33.110000 32.340000 30.740000 30.180000 30.120000 29.38
50% 1959.000000 23.680000 25.480000 29.040000 31.950000 33.510000 32.730000 31.000000 30.540000 30.520000 29.78
75% 1988.000000 24.180000 26.310000 29.610000 32.420000 34.030000 33.180000 31.330000 30.760000 30.810000 30.17
max 2017.000000 26.940000 29.720000 32.620000 35.380000 35.840000 34.480000 32.760000 31.840000 32.220000 32.29
df.head()
0 1901 22.40 24.14 29.07 31.91 33.41 33.18 31.21 30.39 30.47 29.97 27.31 24.49 28.96 23.27 31.46 31.27 27.25
1 1902 24.93 26.58 29.77 31.78 33.73 32.91 30.92 30.73 29.80 29.12 26.31 24.04 29.22 25.75 31.76 31.09 26.49
2 1903 23.44 25.03 27.83 31.39 32.91 33.00 31.34 29.98 29.85 29.04 26.08 23.65 28.47 24.24 30.71 30.92 26.26
3 1904 22.50 24.73 28.21 32.02 32.64 32.07 30.36 30.09 30.04 29.20 26.36 23.63 28.49 23.62 30.95 30.66 26.40
4 1905 22.00 22.83 26.68 30.01 33.32 33.25 31.44 30.68 30.12 30.67 27.52 23.82 28.30 22.25 30.00 31.33 26.57
x=df['YEAR']
y=df['ANNUAL']
plt.figure(figsize=(12,4))
plt.title('temparature plot of india')
plt.xlabel('YEAR')
plt.ylabel('Annual avarage tepm ')
plt.scatter(x,y)
<matplotlib.collections.PathCollection at 0x1fc4f89bdc0>
x.shape
(117,)
x=x.values
x=x.reshape(117,1)
y.shape
(117,)
re=LinearRegression()
re.fit(x,y)
▾ LinearRegression i ?
LinearRegression()
re.coef_
array([0.01312158])
re.intercept_
np.float64(3.4761897126187016)
re.predict([[2024]])
array([30.03427031])
predicted=re.predict(x)
predicted
0 28.96
1 29.22
2 28.47
3 28.49
4 28.30
...
112 29.81
113 29.72
114 29.90
115 31.63
116 31.42
Name: ANNUAL, Length: 117, dtype: float64
y- predicted
0 0.539684
1 0.786563
2 0.023441
3 0.030319
4 -0.172802
...
112 -0.079933
113 -0.183054
114 -0.016176
115 1.700702
116 1.477581
Name: ANNUAL, Length: 117, dtype: float64
import numpy as np
np.mean(abs(y-predicted)**2)
np.float64(0.10960795229110352)
np.float64(0.10960795229110352)
0.6418078912783682
re.score(x,y)
0.6418078912783682
plt.scatter (x,y,label='actual',color='r',marker='.')
plt.plot(x,predicted,label='predicted',color='g')
[<matplotlib.lines.Line2D at 0x1fc791c0970>]
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js