#Identifying and handling the missing values #Feature scaling
[Link]().sum()
from [Link] import MinMaxScaler
mm = MinMaxScaler()
# 1 : Dropna
X_train[:, 3:] = mm.fit_transform(X_train[:, 3:])
df1 = [Link]()
X_test[:, 3:] = [Link](X_test[:, 3:])
# summarize the shape of the raw data
#Standard Scaler
print("Before:",[Link])
from [Link] import StandardScaler
# drop rows with missing values
sta = StandardScaler()
[Link](inplace=True)
X_train[:, 3:] = sta.fit_transform(X_train[:, 3:])
# summarize the shape of the data with missing rows removed
X_test[:, 3:] = [Link](X_test[:, 3:])
print("After:",[Link])
#Fillna
from [Link] import SimpleImputer
df2 = [Link]()
# SimpleImputer to replace NaN with mean
# fill missing values with mean column values imp = SimpleImputer(strategy='mean')
[Link](df2["Age"].mean(),inplace=True)
[Link](df2["Salary"].mean(),inplace=True) # Fit and transform the data
# count the number of NaN values in each column df1_imputed = [Link](imp.fit_transform(df1),
columns=[Link])
print([Link]().sum())
df2
# Print the first 5 rows
print(df1_imputed.head(5))
#Encoding the categorical data
#ColumnTransformer
#Handling Noicy Data
from [Link] import ColumnTransformer
#Function to find outliers
from [Link] import OneHotEncoder
def find_outliers_tukey(x):
ct = ColumnTransformer(transformers=[('encoder',
q1 = [Link](.25)
OneHotEncoder(), [0])], remainder='passthrough')
q3 = [Link](.75)
X = [Link](ct.fit_transform(X))
iqr = q3 - q1
floor = q1 - 1.5*iqr
#LabelEncoder
ceiling = q3 + 1.5*iqr
from [Link] import LabelEncoder
outlier_indices = list([Link][(x < floor) | (x > ceiling)])
le = LabelEncoder()
outlier_values = list(x[outlier_indices])
y = le.fit_transform(y)
return outlier_indices, outlier_values
#Splitting the datase
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)