Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Course Code/Name: 10211CS313 / Machine

Learning Laboratory

Use Case Implementation


Title: Climatic Prediction
Team Members
VTU No Reg No Name
VTU19350 21UECS0461 P.CHAITANYA
VTU19373 21UECM0245 T.NARASIMHA REDDY
VTU19373 21UECM0244 T.DHARMA REDDY
VTU20075 21UECS0484 P.SHASHANK
VTU20640 21UECS0329 SRIKANTH

Aim: To provide information about the future climate to


support decision-making.
Problem Statement: Climate predictions are uncertain due
to the complexity of the climate system and the many factors
that influence its behavior. This uncertainty limits the
usefulness of climate predictions for decision-making.To
address this challenge, we need to improve our understanding
of the climate system, develop more sophisticated climate
models, and better communicate the uncertainty associated
with climate predictions to decision-makers.
Scope: Climate prediction aims to forecast the future
climate, including its variability and change, at different
timescales, to support decision-making.
Methodologies:
• Statistical methods use historical data to identify
relationships between different climate variables, such as
temperature, precipitation, and sea level. These
relationships can then be used to predict future climate
conditions.
• Dynamical methods use the laws of physics to simulate
the Earth's climate system and to predict how it will
respond to changes in external factors, such as
greenhouse gas emissions. Dynamical models are more
complex than statistical models, but they can provide
more detailed and accurate predictions of future climate
conditions.
• Ensemble methods combine the predictions from
multiple climate models to produce a more accurate and
reliable prediction.
• Machine learning methods can be used to identify
patterns in historical climate data that may not be
captured by traditional statistical methods. These patterns
can then be used to predict future climate conditions.
• Analog methods identify historical climate periods that
are similar to current conditions and use the climate
conditions that occurred during those periods to predict
future climate conditions.

Dataset Name: WEATHER PREDICTION


Source URL:
https://www.kaggle.com/datasets/ananthr1/weatherprediction/code

Experimental Setup:
• Software Requirements: Climate prediction
software requirements include programming
languages, scientific computing libraries, climate
model software, and high-performance computing
resources.

• Hardware Requirements: Climate prediction


hardware requirements include powerful CPUs, large
amounts of memory, storage, and networking capabilities.

Implementation (Python Code):


#importing libraries
import pandas as pd import
matplotlib.pyplot as plt import
seaborn as sns import
plotly.express as px
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=
0.30,random_state=42)
data = pd.read_csv('/content/seattle-weather.csv')
data.head(20)
data.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1461 entries, 0 to 1460 Data
columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 date 1461 non-null object
1 precipitation 1461 non-null float64
2 temp_max 1461 non-null float64
3 temp_min 1461 non-null float64
4 wind 1461 non-null float64
5 weather 1461 non-null object dtypes: float64(4),
object(2)
memory usage: 68.6+ KB

data.describe()

data.nunique()

date 1461 precipitation 111 temp_max 67 temp_min 55


wind 79 weather 5 dtype: int64
data['weather'].unique()

array(['drizzle', 'rain', 'sun', 'snow', 'fog'],


dtype=object)

data.isna().sum()

date 0
precipitation 0
temp_max 0
temp_min 0
wind 0 weather
0 dtype: int64
data.index
RangeIndex(start=0, stop=1461,
step=1)

data.columns

Index(['date', 'precipitation', 'temp_max', 'temp_min', 'wind',


'weather'], dtype='object')

data.count()

date 1461
precipitation 1461
temp_max 1461
temp_min 1461
wind 1461
weather 1461
dtype: int64

data['weather'].value_counts()

rain 641
sun 640
fog 101
drizzle 53
snow 26
Name: weather, dtype: int64

data['wind'].unique()
array([4.7, 4.5, 2.3, 6.1, 2.2, 2. , 3.4, 5.1, 1.9, 1.3, 5.3, 3.2, 5. ,
5.6, 1.6, 8.2, 4.8, 3.6, 5.4, 1.4, 3.9, 2.7, 2.6, 4.3, 2.9, 2.4, 3. ,
3.1, 1.8, 2.1, 8.1, 7.5, 5.9, 3.5, 6.4, 4.2, 7. , 6.2, 2.5, 2.8, 5.8,
3.8, 5.2, 4.4, 6.8, 4.1, 4. , 8. , 4.6, 1.5, 6.3, 3.3, 3.7, 1.7, 6. ,
1.1, 7.3, 6.5, 5.7, 5.5, 4.9, 1. , 1.2, 9.5, 0.6, 7.1, 7.6, 0.9, 0.4,
7.9, 7.2, 0.5, 0.7, 8.8, 0.8, 6.6, 6.9, 6.7, 7.7])

data.hist(bins=50,figsize=(5,5))

data.plot(kind='scatter',x='temp_max',y='temp_min',figs
ize=(10,7),)
plt.title("Scatter Plot")
plt.xlabel("temp_max")
plt.ylabel("temp_min")
#feature extraction
X=data[['precipitation','temp_max','temp_min','wind']]
Y=data['weather'] from sklearn.neighbors import
KNeighborsClassifier
KNN = KNeighborsClassifier(n_neighbors=1)
KNN.fit(X,Y)

KNN.score(X,Y)
0.9972621492128679
KNN.predict([[2.5,1.7,-2.8,5.0]])
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439:
UserWarning: X does not have valid feature names, but
KNeighborsClassifier was fitted with feature names
warnings.warn( array(['snow'], dtype=object)
y_pred=KNN.predict(X_test) y_pred
array(['sun', 'rain', 'rain', 'sun', 'rain', 'rain', 'rain', 'sun', 'rain', 'sun',
'sun', 'sun', 'rain', 'sun', 'fog', 'rain', 'sun', 'fog', 'fog', 'sun', 'rain', 'rain',
'rain', 'sun', 'fog', 'rain', 'sun', 'sun', 'fog', 'sun', 'rain', 'sun', 'sun',
'snow', 'sun', 'rain', 'rain', 'rain', 'rain', 'sun', 'rain', 'sun', 'fog', 'sun',
'sun', 'rain', 'rain', 'sun', 'rain', 'sun', 'sun', 'rain', 'sun', 'rain', 'sun',
'rain', 'rain', 'sun', 'rain', 'sun', 'rain', 'sun', 'snow', 'sun', 'sun', 'drizzle',
'rain', 'sun', 'rain', 'rain', 'rain', 'fog', 'sun', 'rain', 'rain', 'sun', 'rain',
'sun', 'rain', 'snow', 'rain', 'drizzle', 'rain', 'sun', 'rain', 'sun', 'drizzle',
'rain', 'fog', 'rain', 'rain', 'sun', 'sun', 'rain', 'rain', 'sun', 'sun', 'rain',
'sun', 'rain', 'sun', 'sun', 'rain', 'snow', 'rain', 'sun', 'sun', 'rain', 'sun',
'rain', 'rain', 'sun', 'rain', 'rain', 'drizzle', 'fog', 'sun', 'sun', 'sun', 'rain',
'rain', 'rain', 'rain', 'rain', 'rain', 'sun', 'sun', 'sun', 'sun', 'sun', 'sun',
'sun', 'sun', 'sun', 'fog', 'sun', 'rain', 'rain', 'rain', 'sun', 'drizzle', 'sun',
'rain', 'rain', 'drizzle', 'fog', 'sun', 'rain', 'sun', 'sun', 'rain', 'sun', 'sun',
'sun', 'rain', 'rain', 'fog', 'sun', 'rain', 'rain', 'sun', 'sun', 'rain', 'sun',
'sun', 'rain', 'rain', 'sun', 'sun', 'sun', 'rain', 'rain', 'fog', 'sun', 'rain',
'rain', 'sun', 'sun', 'sun', 'rain', 'sun', 'sun', 'sun', 'rain', 'rain', 'rain',
'rain', 'rain', 'sun', 'sun', 'drizzle', 'fog', 'sun', 'rain', 'fog', 'sun', 'fog',
'rain', 'snow', 'rain', 'rain', 'sun', 'drizzle', 'rain', 'sun', 'rain', 'rain',
'sun', 'rain', 'sun', 'rain', 'sun', 'sun', 'sun', 'rain', 'sun', 'sun', 'sun',
'rain', 'sun', 'rain', 'sun', 'sun', 'sun', 'fog', 'rain', 'sun', 'rain', 'sun',
'rain', 'sun', 'rain', 'sun', 'sun', 'rain', 'sun', 'sun', 'sun', 'drizzle', 'fog',
'snow', 'rain', 'sun', 'snow', 'sun', 'sun', 'sun', 'sun', 'rain', 'rain', 'rain',
'rain', 'rain', 'fog', 'sun', 'fog', 'rain', 'sun', 'rain', 'rain', 'rain', 'rain',
'rain', 'rain', 'rain', 'fog', 'rain', 'fog', 'fog', 'sun', 'sun', 'sun', 'sun', 'rain',
'sun', 'sun', 'rain', 'snow', 'sun', 'sun', 'fog', 'rain', 'sun', 'sun', 'sun',
'sun', 'rain', 'sun', 'sun', 'rain', 'fog', 'rain', 'sun', 'fog', 'rain', 'rain',
'sun', 'rain', 'rain', 'rain', 'rain', 'rain', 'rain', 'rain', 'rain', 'rain', 'rain',
'drizzle', 'sun', 'sun', 'rain', 'rain', 'rain', 'sun', 'rain', 'sun', 'sun', 'rain',
'sun', 'sun', 'rain', 'rain', 'rain', 'sun', 'sun', 'rain', 'rain', 'drizzle', 'sun',
'sun', 'sun', 'rain', 'rain', 'rain', 'sun', 'sun', 'rain', 'rain', 'rain', 'rain',
'rain', 'sun', 'rain', 'rain', 'sun', 'rain', 'fog', 'rain', 'rain', 'rain', 'sun',
'sun', 'fog', 'rain', 'sun', 'rain', 'sun', 'fog', 'sun', 'fog', 'sun', 'sun', 'sun',
'rain', 'rain', 'rain', 'sun', 'sun', 'sun', 'sun', 'rain', 'rain', 'rain', 'rain',
'rain', 'rain', 'rain', 'rain', 'rain', 'rain', 'rain', 'sun', 'fog', 'sun', 'rain',
'rain', 'rain', 'sun', 'sun', 'rain', 'rain', 'sun', 'sun', 'sun', 'rain', 'sun',
'sun', 'sun', 'rain', 'rain', 'rain', 'sun', 'sun', 'drizzle', 'sun', 'rain', 'sun',
'sun', 'sun', 'sun', 'sun', 'sun', 'sun', 'sun', 'sun', 'sun', 'rain', 'rain',
'sun', 'sun', 'sun', 'sun', 'drizzle', 'sun', 'fog', 'rain', 'sun', 'sun', 'rain',
'sun', 'rain', 'rain', 'sun', 'sun', 'rain', 'rain', 'rain', 'rain', 'drizzle'],
dtype=object)
#predicting classification report from
sklearn.metrics import classification_report
print(classification_report(y_pred,Y_test))

Result:
The results of the project will be the performance the
climate prediction using KNN algorithm. Climate
prediction uses software and hardware to forecast future
climate conditions, helping people and societies prepare
for the impacts of climate change
Sample Screen shots:
Conclusion: In conclusion, this project demonstrates the
climatic prediction using the KNN algorithm. Climate
prediction models are becoming increasingly
sophisticated and accurate, but they are still subject to
uncertainties. However, climate predictions can be used
to support a wide range of decision-making processes,
including managing climate risks, planning for climate
change, and developing climate mitigation policies.

You might also like