CoolFace
Apppublic

Karan1908/Weather-Type-Classification

sourceHugging Faceotherupdated 2y agoView on Hugging Face
0likes
build_features.py52 linesDownload Raw Back to root
1'''2Author       : Karan Chauhan3github       : @Karan-Chauhan194Email        : kc879022@gmail.com5Organization : L.J University6'''7 8#feature Engineering9#Import libraries10 11import pandas as pd12import numpy as np13import matplotlib.pyplot as plt 14import seaborn as sns15from sklearn.preprocessing import StandardScaler,OneHotEncoder16from sklearn.compose import ColumnTransformer17 18class Featureengineering :19 20    def clean_data(self) :21        #Load data22        data = pd.read_csv('weather_classification_data.csv')23        24        #Rename column name25        data.rename(columns={'Wind Speed':'Wind_Speed','Cloud Cover':'Cloud_Cover','Atmospheric Pressure':'Atmospheric_Pressure'26                   ,'UV Index':'UV_Index','Weather Type':'WeatherType'},inplace=True)27        28        #Replace outliers in Temperature and Atmospheric pressure column using capping method29        upper_limit = data['Temperature'].mean() + 3*data['Temperature'].std()30        lower_limit = data['Temperature'].mean() - 3*data['Temperature'].std()31        data['Temperature'] = np.where(data['Temperature']>upper_limit,upper_limit32                             ,np.where(data['Temperature']<lower_limit,lower_limit,data['Temperature']))33        34        data['Atmospheric_Pressure'] = np.where(data['Atmospheric_Pressure']>1100,1085,35                                      np.where(data['Atmospheric_Pressure']<870,885,data['Atmospheric_Pressure']))36        37 38        return data39 40    def get_clean_data(self) :41        df = Featureengineering().clean_data()42        categorical_column = ['Cloud_Cover','Season']43        numerical_column = ['Temperature', 'Humidity', 'Wind_Speed', 'Precipitation (%)','Atmospheric_Pressure', 'UV_Index','Visibility (km)']44        #For feature engineering we use columntransformer45        preprocessor = ColumnTransformer(transformers=[46            ('trf1',OneHotEncoder(drop='first'),categorical_column),47            ('trf2',StandardScaler(),numerical_column)48        ])49 50        return df,preprocessor51        52