-
Notifications
You must be signed in to change notification settings - Fork 3
/
traditional_personalized.py
64 lines (47 loc) · 1.59 KB
/
traditional_personalized.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
52
53
54
55
56
57
58
59
60
61
62
from __future__ import absolute_import, division, print_function
from sklearn.preprocessing import MinMaxScaler
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
from keras.models import Model
import collections
import numpy as np
import tensorflow as tf
import tensorflow_federated as tff
# first neural network with keras tutorial
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
# first neural network with keras tutorial
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
import pandas as pd
X_train= pd.read_csv('./personal_HR/26.csv')
values = X_train.values
values = values.astype('float32')
# normalize features
scaler = MinMaxScaler(feature_range=(0, 1))
scaled = scaler.fit_transform(values)
# frame as supervised learning
train = scaled[:, :]
# split into input and outputs
X, y = train[:, :-1], train[:, -1]
test = SelectKBest(score_func=chi2, k=4)
fit = test.fit(X, y)
# Summarize scores
np.set_printoptions(precision=3)
print(fit.scores_)
features = fit.transform(X)
# Summarize selected features
print(features[0:5,:])
model = Sequential()
model.add(Dense(100, input_dim=16, activation='relu'))
model.add(Dense(100, activation='relu'))
model.add(Dense(100, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
from keras.optimizers import SGD
opt = SGD(lr=0.0001)
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])
model.fit(X, y, epochs=50, batch_size=1)
_, accuracy = model.evaluate(X, y)
print('Accuracy: %.2f' % (accuracy*100))