<jupyter_start><jupyter_text>Imporing Required Libraries<jupyter_code>#importing required libraries for preprosseing
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Importing the data<jupyter_code>data=pd.read_csv('Pre_Data.csv')
print(data.head())<jupyter_output>Country   Age   Salary Purchased
0   France  44.0  72000.0        No
1    Spain  27.0  48000.0       Yes
2  Germany  30.0  54000.0        No
3    Spain  38.0  61000.0        No
4  Germany  40.0      NaN       Yes<jupyter_text>Getting Attrributes of data<jupyter_code>print(data.shape)
print(data.info())
data.describe()<jupyter_output><empty_output><jupyter_text>Checking for null entries in data<jupyter_code>data.isnull().sum()<jupyter_output><empty_output><jupyter_text>Handling Null Values<jupyter_code>from sklearn.impute import SimpleImputer
si=SimpleImputer(missing_values=np.nan,strategy='mean')
data.iloc[:,1:3]=si.fit_transform(data.iloc[:,1:3])
data.isnull().sum()<jupyter_output><empty_output><jupyter_text>Splitting the data into dependent and independent groups<jupyter_code>x=data.iloc[:,0:-1].values
y=data.iloc[:,-1].values
print(x)
print(y)<jupyter_output>['No' 'Yes' 'No' 'No' 'Yes' 'Yes' 'No' 'Yes' 'No' 'Yes']<jupyter_text>Splitting data into train and test data<jupyter_code>from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct=ColumnTransformer([('encoder', OneHotEncoder(), [0])],remainder='passthrough')
x=np.array(ct.fit_transform(x),dtype=np.str)
print(x)<jupyter_output>[['1.0' '0.0' '0.0' '44.0' '72000.0']
 ['0.0' '0.0' '1.0' '27.0' '48000.0']
 ['0.0' '1.0' '0.0' '30.0' '54000.0']
 ['0.0' '0.0' '1.0' '38.0' '61000.0']
 ['0.0' '1.0' '0.0' '40.0' '63777.77777777778']
 ['1.0' '0.0' '0.0' '35.0' '58000.0']
 ['0.0' '0.0' '1.0' '38.77777777777778' '52000.0']
 ['1.0' '0.0' '0.0' '48.0' '79000.0']
 ['0.0' '1.0' '0.0' '50.0' '83000.0']
 ['1.0' '0.0' '0.0' '37.0' '67000.0']]<jupyter_text>Encoding Dependent Variable<jupyter_code>from sklearn.preprocessing import LabelEncoder
LB=LabelEncoder()
y=LB.fit_transform(y)
print(y)<jupyter_output>[0 1 0 0 1 1 0 1 0 1]<jupyter_text>Splitting data into train and test data<jupyter_code>from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=1)<jupyter_output><empty_output><jupyter_text>Feature Scalinng<jupyter_code>from sklearn.preprocessing import StandardScaler
SC=StandardScaler()
x_train[:, 3:]=SC.fit_transform(x_train[:, 3:])
x_test[:, 3:]=SC.fit(x_test[:, 3:])
print(x_train)<jupyter_output>[['0.0' '0.0' '1.0' '-0.19159184384578' '-1.07812594084124']
 ['0.0' '1.0' '0.0' '-0.01411729375705' '-0.07013167641635']
 ['1.0' '0.0' '0.0' '0.566708506533324' '0.633562432710455']
 ['0.0' '0.0' '1.0' '-0.30453019390224' '-0.30786617274297']
 ['0.0' '0.0' '1.0' '-1.90180114470079' '-1.42046361555158']
 ['1.0' '0.0' '0.0' '1.147534306823705' '1.232653363453549']
 ['0.0' '1.0' '0.0' '1.437947206968896' '1.574991038163888']
 ['1.0' '0.0' '0.0' '-0.74014954412003' '-0.56461942877573']]
{'fraction_non_alphanumeric': 0.19266645223544548, 'fraction_numerical': 0.17240270183338693, 'mean_word_length': 5.850220264317181, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '164479', 'license': 'Apache-2.0', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1419, 'n_words': 232, 'path': 'Pre_Processing.ipynb', 'repo_name': 'Legolas1086/ML_preprocessing', 'size': '3109'}