<gh_stars>1-10
# -*- coding: utf-8 -*-
"""DeepLearning.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1rHqtJx10YXjJe_mWbt0-4e0wz9Hwrycu
"""

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

veriler = pd.read_csv('/content/Churn_Modelling.csv')

X = veriler.iloc[:, 3:-1]
Y = veriler.iloc[:, -1]
# NUMPY ARRAY DIZI DONUSUMU
x = X.values
y = Y.values

from sklearn import preprocessing
from sklearn.compose import ColumnTransformer # birden fazla ozelligi ayni anda ayri ayri donusturur | Hetorojen yapiyi alip tek seferde donusum yapar.

le = preprocessing.LabelEncoder()
x[:, 1] = le.fit_transform(x[:, 1])
x[:, 2] = le.fit_transform(x[:, 2])

ohe = ColumnTransformer(
    [("ohe", preprocessing.OneHotEncoder(dtype = 'float'), [1])],
    remainder = "passthrough" # kalanlari birak
)

x = ohe.fit_transform(x)
x = x[:, 1:]

x[1, :]

from sklearn.model_selection import train_test_split

# verinin yuzde 66 si antrenman icin kullanilsin kalan yuzde 33'u test edilsin diye ayrdik
# random_state rastsal ayirma icin kullaniliyor ayni degeri alan her kod ayni ayrimi yapar
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.33, random_state = 0)

from sklearn.preprocessing import StandardScaler

sc = StandardScaler()

# burasi bir tur normalizasyon islemi anlatiyor (x-mean)/standar_deviation denklemini kullanir
X_train = sc.fit_transform(x_train)
X_test = sc.fit_transform(x_test)

X_train

"""**YSA**"""

from keras.models import Sequential
from keras.layers import Dense

model = Sequential()
model.add(Dense(6, kernel_initializer = "uniform", activation = "relu", input_dim = 11, name = "gir"))
model.add(Dense(6, kernel_initializer = "uniform", activation = "relu", name = 'ara1'))
model.add(Dense(1, kernel_initializer = "uniform", activation = "sigmoid", name = 'cik'))

model.compile(optimizer = 'Adam',             # it is a form of stochastic gradient
              loss = 'binary_crossentropy',
              metrics = ['accuracy']) 
model.fit(X_train, y_train, epochs = 50)
y_pred = model.predict(X_test)
y_pred = y_pred > 0.5

from sklearn.metrics import confusion_matrix

cm = confusion_matrix(y_test, y_pred)
cm


# -*- coding: utf-8 -*-
"""DeepLearning.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1rHqtJx10YXjJe_mWbt0-4e0wz9Hwrycu
"""

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

veriler = pd.read_csv('/content/Churn_Modelling.csv')

X = veriler.iloc[:, 3:-1]
Y = veriler.iloc[:, -1]
# NUMPY ARRAY DIZI DONUSUMU
x = X.values
y = Y.values

from sklearn import preprocessing
from sklearn.compose import ColumnTransformer # birden fazla ozelligi ayni anda ayri ayri donusturur | Hetorojen yapiyi alip tek seferde donusum yapar.

le = preprocessing.LabelEncoder()
x[:, 1] = le.fit_transform(x[:, 1])
x[:, 2] = le.fit_transform(x[:, 2])

ohe = ColumnTransformer(
    [("ohe", preprocessing.OneHotEncoder(dtype = 'float'), [1])],
    remainder = "passthrough" # kalanlari birak
)

x = ohe.fit_transform(x)
x = x[:, 1:]

x[1, :]

from sklearn.model_selection import train_test_split

# verinin yuzde 66 si antrenman icin kullanilsin kalan yuzde 33'u test edilsin diye ayrdik
# random_state rastsal ayirma icin kullaniliyor ayni degeri alan her kod ayni ayrimi yapar
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.33, random_state = 0)

from sklearn.preprocessing import StandardScaler

sc = StandardScaler()

# burasi bir tur normalizasyon islemi anlatiyor (x-mean)/standar_deviation denklemini kullanir
X_train = sc.fit_transform(x_train)
X_test = sc.fit_transform(x_test)

X_train

"""**YSA**"""

from keras.models import Sequential
from keras.layers import Dense

model = Sequential()
model.add(Dense(6, kernel_initializer = "uniform", activation = "relu", input_dim = 11, name = "gir"))
model.add(Dense(6, kernel_initializer = "uniform", activation = "relu", name = 'ara1'))
model.add(Dense(1, kernel_initializer = "uniform", activation = "sigmoid", name = 'cik'))

model.compile(optimizer = 'Adam',             # it is a form of stochastic gradient
              loss = 'binary_crossentropy',
              metrics = ['accuracy']) 
model.fit(X_train, y_train, epochs = 50)
y_pred = model.predict(X_test)
y_pred = y_pred > 0.5

from sklearn.metrics import confusion_matrix

cm = confusion_matrix(y_test, y_pred)
cm
# -*- coding: utf-8 -*- DeepLearning.ipynb  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/1rHqtJx10YXjJe_mWbt0-4e0wz9Hwrycu # NUMPY ARRAY DIZI DONUSUMU # birden fazla ozelligi ayni anda ayri ayri donusturur | Hetorojen yapiyi alip tek seferde donusum yapar. # kalanlari birak # verinin yuzde 66 si antrenman icin kullanilsin kalan yuzde 33'u test edilsin diye ayrdik # random_state rastsal ayirma icin kullaniliyor ayni degeri alan her kod ayni ayrimi yapar # burasi bir tur normalizasyon islemi anlatiyor (x-mean)/standar_deviation denklemini kullanir **YSA** # it is a form of stochastic gradient