Skip to content

Instantly share code, notes, and snippets.

@JoseRFJuniorLLMs
Created January 27, 2018 05:32
Show Gist options
  • Save JoseRFJuniorLLMs/232b25dac30d426a58c0e29c1dbba64d to your computer and use it in GitHub Desktop.
Save JoseRFJuniorLLMs/232b25dac30d426a58c0e29c1dbba64d to your computer and use it in GitHub Desktop.
# Data Preprocessing
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
#Cuidando dados faltantes
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0)
imputer = imputer.fit(X[:, 1:3])
X[:, 1:3] = imputer.transform(X[:, 1:3])
# Codificação de dados categóricos
# Codificando a Variável Independente
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X = LabelEncoder()
X[:, 0] = labelencoder_X.fit_transform(X[:, 0])
onehotencoder = OneHotEncoder(categorical_features = [0])
X = onehotencoder.fit_transform(X).toarray()
# Codificando a Variável Dependente
labelencoder_y = LabelEncoder()
y = labelencoder_y.fit_transform(y)
print("X>",X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment