GithubHelp home page GithubHelp logo

lalogarces / data-preprocessing-machine-learning-template Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 284 KB

This is an essential and must have template before to run any Machine Learning Model

License: The Unlicense

Jupyter Notebook 100.00%
colab-notebook data-science datapreprocessing dataprocessing machine-learning machinelearning python template templates

data-preprocessing-machine-learning-template's Introduction

Data Preprocessing Machine Learning Template

This is a Colab Template to be used as Data Preprocessing step before apply any ML Model. Within the Notebook, you will find the explanation and details of the “Why” of these steps presented on this template.

In this template, we present this 6 essential preprocessing steps:

  • Importing libraries
  • Importing the dataset
  • Deal with missing data
  • Encode categorical data
  • Split the dataset into Training and Test
  • Feature Scaling

1.- Importing libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sklearn as sk

2.- Importing dataset

from google.colab import drive
drive.mount("/content/gdrive")
from google.colab import files
uploaded = files.upload()

dataset = pd.read_csv("dataset.csv")

3.- Deal with missing data

from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
imputer.fit(x[:, :])
x[:, :] = imputer.transform(x[:, :])

4.- Encoding Categorical Data

from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [])], remainder='passthrough')
x = np.array(ct.fit_transform(x))

5.- Split the data into Training and Test Set

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)

6.- Feature Scaling

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x_train[:,:] = sc.fit_transform(x_train[:, :])
x_test[:, :] = sc.fit_transform(x_test[:, :])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.