0% found this document useful (0 votes)
16 views4 pages

Practical No. 09.ipynb - Colab

Uploaded by

Chetan Aher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Practical No. 09.ipynb - Colab

Uploaded by

Chetan Aher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

10/14/24, 1:59 PM practical no. 09.

ipynb - Colab

#Guru Gobind Singh College of Engineering and Research Centre, Nashik


# Subject Name : Numerical and Statistical Methods (302041)
# Year & Class : Third Year Mechanical Engineering (2019 Pattern)
# Name of Student : Prashant Ashok Sumb
# Roll.no.: 29 # Batch no.: A2
# Date of Performance : 14/10/2024
# Title of Experiment : : To develop regression model and evaluate its performance

## STEP 1: Importing the Liabraries ##


import pandas as pd
import numpy as np
from sklearn import linear_model
import matplotlib.pyplot as plt

## STEP 2:Uploading the Dataset ##


from google.colab import files
uploaded = files.upload()
import io
df = pd.read_csv(io.BytesIO(uploaded['temperatures.csv']))
df

Choose Files temperatures.csv


temperatures.csv(text/csv) - 12487 bytes, last modified: 10/14/2024 - 100% done
Saving temperatures.csv to temperatures.csv
JAN- MAR- JUN- OCT-
YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ANNUAL
FEB MAY SEP DEC

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

... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

112 2013 24.56 26.59 30.62 32.66 34.46 32.44 31.07 30.76 31.04 30.27 27.83 25.37 29.81 25.58 32.58 31.33 27.83

113 2014 23.83 25.97 28.95 32.74 33.77 34.15 31.85 31.32 30.68 30.29 28.05 25.08 29.72 24.90 31.82 32.00 27.81

114 2015 24.58 26.89 29.07 31.87 34.09 32.48 31.88 31.52 31.55 31.04 28.10 25.67 29.90 25.74 31.68 31.87 28.27

115 2016 26.94 29.72 32.62 35.38 35.72 34.03 31.64 31.79 31.66 31.98 30.11 28.01 31.63 28.33 34.57 32.28 30.03

116 2017 26.45 29.46 31.60 34.95 35.84 33.82 31.88 31.72 32.22 32.29 29.60 27.18 31.42 27.95 34.13 32.41 29.69

Next steps: Generate code with df


toggle_off View recommended plots New interactive sheet

## STEP 3: Analysis of Dataset ##


df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 117 entries, 0 to 116
Data columns (total 18 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 YEAR 117 non-null int64
1 JAN 117 non-null float64
2 FEB 117 non-null float64
3 MAR 117 non-null float64
4 APR 117 non-null float64
5 MAY 117 non-null float64
6 JUN 117 non-null float64
7 JUL 117 non-null float64
8 AUG 117 non-null float64
9 SEP 117 non-null float64
10 OCT 117 non-null float64
11 NOV 117 non-null float64
12 DEC 117 non-null float64
13 ANNUAL 117 non-null float64
14 JAN-FEB 117 non-null float64
15 MAR-MAY 117 non-null float64
16 JUN-SEP 117 non-null float64
17 OCT-DEC 117 non-null float64
dtypes: float64(17), int64(1)
memory usage: 16.6 KB

df.describe()

https://colab.research.google.com/drive/1uvB1hOz1iI0EvLlKnZ3K_NnMVHJaYTig#scrollTo=qlS6zgHYETOR&printMode=true 1/4
10/14/24, 1:59 PM practical no. 09.ipynb - Colab

YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OCT

count 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000

mean 1959.000000 23.687436 25.597863 29.085983 31.975812 33.565299 32.774274 31.035897 30.507692 30.486752 29.766581

std 33.919021 0.834588 1.150757 1.068451 0.889478 0.724905 0.633132 0.468818 0.476312 0.544295 0.705492

min 1901.000000 22.000000 22.830000 26.680000 30.010000 31.930000 31.100000 29.760000 29.310000 29.070000 27.900000

25% 1930.000000 23.100000 24.780000 28.370000 31.460000 33.110000 32.340000 30.740000 30.180000 30.120000 29.380000

50% 1959.000000 23.680000 25.480000 29.040000 31.950000 33.510000 32.730000 31.000000 30.540000 30.520000 29.780000

75% 1988.000000 24.180000 26.310000 29.610000 32.420000 34.030000 33.180000 31.330000 30.760000 30.810000 30.170000

max 2017.000000 26.940000 29.720000 32.620000 35.380000 35.840000 34.480000 32.760000 31.840000 32.220000 32.290000

## STEP 4: Visuliaze the dataset


%matplotlib inline
plt.xlabel('YEAR')
plt.ylabel('JAN')
plt.scatter(df.YEAR,df.JAN,color='red',marker='*')

<matplotlib.collections.PathCollection at 0x7afa0a6bbd30>

## STEP 5: Extract the data ##


new_df=df
new_df.drop(df.iloc[:, 2:18], inplace = True, axis = 1)
new_df

YEAR JAN

0 1901 22.40

1 1902 24.93

2 1903 23.44

3 1904 22.50

4 1905 22.00

... ... ...

112 2013 24.56

113 2014 23.83

114 2015 24.58

115 2016 26.94

116 2017 26.45

117 rows × 2 columns

Next steps: Generate code with df


toggle_off View recommended plots New interactive sheet

new_df=new_df.drop('JAN',axis='columns')
new_df

https://colab.research.google.com/drive/1uvB1hOz1iI0EvLlKnZ3K_NnMVHJaYTig#scrollTo=qlS6zgHYETOR&printMode=true 2/4
10/14/24, 1:59 PM practical no. 09.ipynb - Colab

YEAR

0 1901

1 1902

2 1903

3 1904

4 1905

... ...

112 2013

113 2014

114 2015

115 2016

116 2017

117 rows × 1 columns

Next steps: Generate code with new_df


toggle_off View recommended plots New interactive sheet

JanTemp = df.JAN
JanTemp

JAN

0 22.40

1 24.93

2 23.44

3 22.50

4 22.00

... ...

112 24.56

113 23.83

114 24.58

115 26.94

116 26.45

117 rows × 1 columns

dtype: float64

print(new_df)

YEAR
0 1901
1 1902
2 1903
3 1904
4 1905
.. ...
112 2013
113 2014
114 2015
115 2016
116 2017

[117 rows x 1 columns]

## STEP 6: Create linear regression object


reg = linear_model.LinearRegression()
reg.fit(new_df,JanTemp)

▾ LinearRegression i ?
LinearRegression()

reg.coef_

https://colab.research.google.com/drive/1uvB1hOz1iI0EvLlKnZ3K_NnMVHJaYTig#scrollTo=qlS6zgHYETOR&printMode=true 3/4
10/14/24, 1:59 PM practical no. 09.ipynb - Colab

array([0.01416034])

reg.intercept_

-4.052660537397539

## STEP 7: Prediction of temperature


reg.predict([[2019]])

/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: UserWarning: X does not have valid feature names, but LinearRegression
warnings.warn(
array([24.537056])

https://colab.research.google.com/drive/1uvB1hOz1iI0EvLlKnZ3K_NnMVHJaYTig#scrollTo=qlS6zgHYETOR&printMode=true 4/4

You might also like