<jupyter_start><jupyter_text>Data Preproccessing Steps  Import Library<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot<jupyter_output><empty_output><jupyter_text>Import Dataset<jupyter_code>dataset=pd.read_csv('C:\\Users\\YogeshR\\Downloads\\Machine Learning A-Z (Codes and Datasets)\\Part 1 - Data Preprocessing\\1\\Python\\data.csv')

x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
print(x)
print(y)<jupyter_output>['No' 'Yes' 'No' 'No' 'Yes' 'Yes' 'No' 'Yes' 'No' 'Yes']<jupyter_text>Handling the missing data<jupyter_code>from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy= 'mean')
imputer.fit(x[:,1:3])
(x[:,1:3])=imputer.transform(x[:,1:3])
print(x)<jupyter_output>[['France' 44.0 72000.0]
 ['Spain' 27.0 48000.0]
 ['Germany' 30.0 54000.0]
 ['Spain' 38.0 61000.0]
 ['Germany' 40.0 63777.77777777778]
 ['France' 35.0 58000.0]
 ['Spain' 38.77777777777778 52000.0]
 ['France' 48.0 79000.0]
 ['Germany' 50.0 83000.0]
 ['France' 37.0 67000.0]]<jupyter_text>Encoding Independent Varaibles<jupyter_code>from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder',OneHotEncoder(),[0])],remainder='passthrough')
x = np.array(ct.fit_transform(x))
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 Varaiables<jupyter_code>from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
y = le.fit_transform(y)
print(y)<jupyter_output>[0 1 0 0 1 1 0 1 0 1]<jupyter_text>Splitting The Dataset Into Training Set And Test Set<jupyter_code>from sklearn.model_selection import train_test_split
xtrain,xtest,ytrain,ytest = train_test_split(x,y,test_size= 0.2,random_state = 1)
print(xtrain)
print(xtest)
print(ytrain)
print(ytest)<jupyter_output>[0 1]<jupyter_text>Feature Scaling<jupyter_code>from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
xtrain[:, 3:] = sc.fit_transform(xtrain[:, 3:])
xtest[:, 3:] = sc.transform(xtest[:, 3:])
print(xtrain)
print(xtest)<jupyter_output>[[0.0 1.0 0.0 -1.4661817944830124 -0.9069571034860727]
 [1.0 0.0 0.0 -0.44973664397484414 0.2056403393225306]]
StarcoderdataJupyterStructuredCleanDedup