0% found this document useful (0 votes)
2 views3 pages

Practical 9 Python Code

This document outlines a project from Guru Gobind Singh College of Engineering and Research Centre focused on developing a regression model to evaluate temperature data. It includes steps for importing libraries, uploading a dataset, analyzing the dataset, visualizing data, and creating a linear regression model to predict January temperatures. The dataset consists of historical temperature data from 1901 to 2017, and the model predicts a temperature of approximately 24.54°C for January 2019.

Uploaded by

Ashish Dhage
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)
2 views3 pages

Practical 9 Python Code

This document outlines a project from Guru Gobind Singh College of Engineering and Research Centre focused on developing a regression model to evaluate temperature data. It includes steps for importing libraries, uploading a dataset, analyzing the dataset, visualizing data, and creating a linear regression model to predict January temperatures. The dataset consists of historical temperature data from 1901 to 2017, and the model predicts a temperature of approximately 24.54°C for January 2019.

Uploaded by

Ashish Dhage
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

add Code add Text

# 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:
# Roll No. : # Batch No.:
# Date of Performance:
# Title of Experiments: 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 [Link] as plt

## STEP 2: Uploading the Dataset ##


from [Link] import files
uploaded = [Link]()
import io
df = pd.read_csv([Link](uploaded['[Link]']))
df

Choose Files No file chosen Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to enable.
Saving [Link] to [Link]
YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ANNUAL JAN-FEB MAR-MAY JUN-SEP OCT-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

117 rows × 18 columns

## STEP 3: Analysis of Dataset ##


[Link]()

<class '[Link]'>
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

[Link]()

YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ANNUAL JAN-

count 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000000 117.000

mean 1959.000000 23.687436 25.597863 29.085983 31.975812 33.565299 32.774274 31.035897 30.507692 30.486752 29.766581 27.285470 24.608291 29.181368 24.629

std 33.919021 0.834588 1.150757 1.068451 0.889478 0.724905 0.633132 0.468818 0.476312 0.544295 0.705492 0.714518 0.782644 0.555555 0.911

min 1901.000000 22.000000 22.830000 26.680000 30.010000 31.930000 31.100000 29.760000 29.310000 29.070000 27.900000 25.700000 23.020000 28.110000 22.250

25% 1930.000000 23.100000 24.780000 28.370000 31.460000 33.110000 32.340000 30.740000 30.180000 30.120000 29.380000 26.790000 24.040000 28.760000 24.110

50% 1959.000000 23.680000 25.480000 29.040000 31.950000 33.510000 32.730000 31.000000 30.540000 30.520000 29.780000 27.300000 24.660000 29.090000 24.530

75% 1988.000000 24.180000 26.310000 29.610000 32.420000 34.030000 33.180000 31.330000 30.760000 30.810000 30.170000 27.720000 25.110000 29.470000 25.150

max 2017.000000 26.940000 29.720000 32.620000 35.380000 35.840000 34.480000 32.760000 31.840000 32.220000 32.290000 30.110000 28.010000 31.630000 28.330

## STEP 4: Visuliaze the dataset


%matplotlib inline
[Link]('YEAR')
[Link]('JAN')
[Link]([Link],[Link],color='red',marker='*')
<[Link] at 0x7d439362ab90>

## STEP 5: Extract the data ##


new_df=df
new_df.drop([Link][:, 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

new_df=new_df.drop('JAN',axis='columns')
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 × 1 columns

JanTemp = [Link]
JanTemp

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
Name: JAN, Length: 117, 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()
[Link](new_df,JanTemp)

▾ LinearRegression
LinearRegression()

reg.coef_

array([0.01416034])

reg.intercept_

-4.052660537397539

## STEP 7: Prediction of temperature


[Link]([[2019]])

/usr/local/lib/python3.10/dist-packages/sklearn/[Link]: UserWarning: X does not have valid feature names, but LinearRegression was fitted with feature names
[Link](
array([24.537056])

You might also like