forked from saipraveenpn/rvce-coding-club-ml-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessing.py
More file actions
53 lines (39 loc) · 1.2 KB
/
preprocessing.py
File metadata and controls
53 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pandas as pd
import numpy as np
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder
# Importing the dataset
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
#Replacing missing values
imputer = SimpleImputer(missing_values = np.nan , strategy = 'mean')
X[:, 1:3] = imputer.fit_transform(X[:, 1:3])
#Rescaling
#from sklearn.preprocessing import MinMaxScaler
#
#data = [[-1, 2], [-0.5, 6], [0, 5], [1, 15]]
#scaler = MinMaxScaler((1,15))
#scaler.fit(data)
#print(scaler.transform(data))
#Standardising
#from sklearn.preprocessing import StandardScaler
#
#data = [[0, 0], [0, 0], [1, 1], [1, 1]]
#scaler = StandardScaler()
#print(scaler.fit(data))
#print(scaler.mean_)
#print(scaler.transform(data))
#Binariser
#from sklearn.preprocessing import Binarizer
#X = [[ 1., -1., 2.],
# [ 2., 0., 0.],
# [ 0., 1., -1.]]
#y = Binarizer( threshold=1).fit_transform(X)
#Label Encoder
#from sklearn.preprocessing import LabelEncoder
#le = LabelEncoder()
#print(le.fit_transform(X[:,0]))
#X[:,0] = le.fit_transform(X[:,0])
onehotencoder = OneHotEncoder(categorical_features = [0])
X = onehotencoder.fit_transform(X).toarray()