# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/harshadhosewann/Data-Analytics/blob/main/Data_Preprocessing.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="0hE-Nq8-Vcwp"
import pandas as pd
df = pd.read_csv("data.csv")

# + colab={"base_uri": "https://localhost:8080/"} id="d9PAPUgZW_ia" outputId="7c894b92-c3d0-4bb0-f520-09bd477ab4d6"
df.dtypes

# + id="QmRhyh0fW_1H"
X = df.iloc[:,:-1].values
Y = df.iloc[:,-1].values 

# + colab={"base_uri": "https://localhost:8080/"} id="RadpdZw9W_7a" outputId="cf033cd4-dede-4239-f567-fbd54971d40a"
X

# + colab={"base_uri": "https://localhost:8080/"} id="7zUiIw4YXACI" outputId="58d0e45c-6af0-43bd-b9f3-438f7e23237f"
Y

# + [markdown] id="wyjfRKjcbv3k"
# **Encoding categorical data**

# + [markdown] id="Oapx8KPPbgxW"
# **Encoding the independent data**
#
#
#

# + id="FSra9LrpXAIT"
import numpy as np
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])

# + colab={"base_uri": "https://localhost:8080/"} id="06uzi5BzmUu7" outputId="70721b1d-3bee-4d94-c9b9-dff22fee7f78"
X

# + [markdown] id="AEUxc3DYa6wh"
# **Encoding the dependent variable** 
#

# + id="NmcHiMRlXANv"
from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()
Y = le.fit_transform(Y)

# + colab={"base_uri": "https://localhost:8080/"} id="0zl0LqpaXAQ7" outputId="d26746c9-463e-4ffd-caf5-428780628c38"
Y

# + id="GthKctsemrvQ"
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))

# + colab={"base_uri": "https://localhost:8080/"} id="6Y0NNdzDn-gK" outputId="bd4228a3-76d2-4a44-e6f0-9d8293c55c04"
X

# + id="gx1mX4PnoFBB"
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
Y = le.fit_transform(Y)

# + colab={"base_uri": "https://localhost:8080/"} id="Iw814snOoHGq" outputId="415980b8-86a2-442b-d3ed-56f0d418c882"
Y

# + [markdown] id="JH3rpmsPcItS"
# **Splitting the dataset into Training set and Test set**

# + id="jUDdTx1qcTSy"
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)

# + colab={"base_uri": "https://localhost:8080/"} id="vI6hb4W2mEmi" outputId="afb4fce3-e595-4c57-94a0-4219aef694cb"
X_train

# + colab={"base_uri": "https://localhost:8080/"} id="EJXm6u6gmEwo" outputId="012c7778-01d5-4e5e-f1aa-4dc45703987c"
X_test

# + colab={"base_uri": "https://localhost:8080/"} id="_vmoJhIcmE14" outputId="79e39f4a-e2a0-4ca7-8fa8-40fec6f65111"
Y_train

# + colab={"base_uri": "https://localhost:8080/"} id="PMAlalahmFUx" outputId="7517fcc0-6f63-49e6-8ad0-9c8fe932d686"
Y_test

# + [markdown] id="9NWGwzQgqVCy"
# **Features Scaling**

# + id="uYlMsgtfqbM2"
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train[:,3:] = sc.fit_transform(X_train[:,3:])
X_test = sc.transform(X_test[:,3:])

# + colab={"base_uri": "https://localhost:8080/"} id="5rPMmfPSqbUt" outputId="2b676412-1a37-4015-f90c-7215271682f3"
X_train

# + colab={"base_uri": "https://localhost:8080/"} id="VxlNBAVvqbc9" outputId="ffccd826-67eb-407c-c12e-43a7f73edd41"
X_test

StarcoderdataJupyterScriptsDedupFiltered