> Structured Data Classification Hands-on Solutions - TECH UPDATE

Structured Data Classification Hands-on Solutions

Structured Data Classification Hands-on Solutions 



The Course Id of the Structured Data Classification is 55941.

Structured_test

step 1: - 

import pandas as pd

import numpy as np

import dataframe as df

step 2:- 

weather = pd.read_csv('weather.csv', sep=',')

step 3:- 

data_size=weather.shape

print(data_size)

weather_col_names = list(weather.columns)

print(weather_col_names)

print(weather.describe())

print(weather.head(3))

step 4:-

weather_target=weather['RainTomorrow'] 

print(weather_target)

step 5:-

cols_to_drop = ['Date','RainTomorrow']

weather_feature = weather.drop(cols_to_drop,axis = 1)

print(weather_feature.head(5))

step 6: -

weather_categorical = weather.select_dtypes(include=[object])

print(weather_categorical.head(15))

step 7:- 

yes_no_cols = ["RainToday"]

weather_feature[yes_no_cols] = weather_feature[yes_no_cols] == 'Yes'

print(weather_feature.head(5))

step 8:-

weather_dumm=pd.get_dummies(weather_feature, columns=["Location","WindGustDir","WindDir9am","WindDir3pm"], prefix=["Location","WindGustDir","WindDir9am","WindDir3pm"])

weather_matrix = weather_dumm.values.astype(np.float)

step 9:- 

from sklearn.impute import SimpleImputer

imp=SimpleImputer(missing_values=np.nan,strategy='mean', fill_value=None,verbose=0,copy=True)

weather_matrix=imp.fit_transform(weather_matrix)

step 10:-

from sklearn.preprocessing import StandardScaler

#Standardize the data by removing the mean and scaling to unit variance

scaler = StandardScaler()

#Fit to data, then transform it.

weather_matrix = scaler.fit_transform(weather_matrix)

step 11:- 

from sklearn.model_selection import train_test_split

seed=5000

train_data,test_data, train_label, test_label = train_test_split(weather_matrix,weather_target,test_size=0.1,random_state = seed)

step 12:- 

from sklearn.svm import SVC

classifier = SVC(kernel="linear",C=0.025,random_state=seed )

classifier = classifier.fit(train_data,train_label)

churn_predicted_target=classifier.predict(test_data)

score = classifier.score(test_data,test_label)

print('SVM Classifier : ',score)

with open('output.txt', 'w') as file:

    file.write(str(np.mean(score)))


step 13:- 

from sklearn.ensemble import RandomForestClassifier

classifier = RandomForestClassifier(max_depth=5,n_estimators=10,max_features=10,random_state=seed)

classifier = classifier.fit(train_data,train_label)

churn_predicted_target=classifier.predict(test_data)

score = classifier.score(test_data,test_label)

print('Random Forest Classifier : ',score)

with open('output1.txt', 'w') as file:

    file.write(str(np.mean(score)))

Structured Data Classification Hands-on Solutions Structured Data Classification Hands-on Solutions Reviewed by TECH UPDATE on July 20, 2021 Rating: 5

10 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Good concept, Your post is really nice. Very good job, i would you like more information. keep it up.
    https://aditidigitalsolutions.com/aws-training-hyderabad/

    ReplyDelete
  4. How it will start i am confused that in which file i will trpe

    ReplyDelete
  5. Thanks, it was very helpful

    ReplyDelete
  6. In 13th step: gives error as seed is not defined

    ReplyDelete

Powered by Blogger.