-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ann_myone.py
51 lines (38 loc) · 1.4 KB
/
Ann_myone.py
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
# -*- coding: utf-8 -*-
"""
Spyder Editor
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
dataset=pd.read_csv('Churn_Modelling.csv')
X=dataset.iloc[:,3:13].values
Y=dataset.iloc[:,13].values
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
a=LabelEncoder()
X[:,1]=a.fit_transform(X[:,1])
X[:,2]=a.fit_transform(X[:,2])
b=OneHotEncoder(categorical_features=[1])
X=b.fit_transform(X).toarray()
X=X[:,1:]
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=0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
import keras
from keras.layers import Dense
from keras.models import Sequential
model=Sequential()
model.add(Dense(units=6,activation='relu',kernel_initializer='uniform',input_dim=11))
model.add(Dense(units=6,activation='relu',kernel_initializer='uniform'))
model.add(Dense(units=1,activation='sigmoid',kernel_initializer='uniform'))
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
model.fit(x_train,y_train,batch_size=30,epochs=100)
y_pred=model.predict(x_test)
y_pred=(y_pred>0.5)
res = model.predict(sc.transform(np.array([[0.0, 0, 600, 1, 40, 3, 60000, 2, 1, 1, 50000]])))
res = (res > 0.5)
from sklearn.metrics import confusion_matrix
cm=confusion_matrix(y_test,y_pred)