-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (39 loc) · 1.39 KB
/
main.py
File metadata and controls
47 lines (39 loc) · 1.39 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
import numpy as np
import pandas as pd
from sklearn.impute import SimpleImputer as sp
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# Importing the dataset
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
# print(X)
# print(y)
# Missing value with nan
impute = sp(missing_values=np.nan, strategy='mean')
H = impute.fit(X[:, 1:3])
X[:, 1:3] = impute.transform(X[:, 1:3])
# print(X)
# Encode column to make easy to run with ml --> convert category to three column like iq qp ln ==> 100 010 001
ColumnTrans = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [0])], remainder='passthrough')
X = np.array(ColumnTrans.fit_transform(X))
# print(X)
# Encode column to make easy to run with ml --> convert category in one column like yse not ==> 0 1
y = LabelEncoder().fit_transform(y)
# print(y)
# Train and Test
# Splitting dbs to tran and test it
X_train, X_test, Y_Train, Y_test = train_test_split(X, y, test_size=0.2, random_state=1)
# print(X_train)
# print(X_test)
# print(Y_Train)
# print(Y_test)
# feature Scaling
sc = StandardScaler()
X_train[:, 3:] = sc.fit_transform(X_train[:, 3:])
X_test[:, 3:] = sc.transform(X_test[:, 3:])
print(X_train)
print(X_test)