-
Notifications
You must be signed in to change notification settings - Fork 152
/
main_letter_spam.py
107 lines (88 loc) · 2.73 KB
/
main_letter_spam.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# coding=utf-8
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''Main function for UCI letter and spam datasets.
'''
# Necessary packages
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import numpy as np
from data_loader import data_loader
from gain import gain
from utils import rmse_loss
def main (args):
'''Main function for UCI letter and spam datasets.
Args:
- data_name: letter or spam
- miss_rate: probability of missing components
- batch:size: batch size
- hint_rate: hint rate
- alpha: hyperparameter
- iterations: iterations
Returns:
- imputed_data_x: imputed data
- rmse: Root Mean Squared Error
'''
data_name = args.data_name
miss_rate = args.miss_rate
gain_parameters = {'batch_size': args.batch_size,
'hint_rate': args.hint_rate,
'alpha': args.alpha,
'iterations': args.iterations}
# Load data and introduce missingness
ori_data_x, miss_data_x, data_m = data_loader(data_name, miss_rate)
# Impute missing data
imputed_data_x = gain(miss_data_x, gain_parameters)
# Report the RMSE performance
rmse = rmse_loss (ori_data_x, imputed_data_x, data_m)
print()
print('RMSE Performance: ' + str(np.round(rmse, 4)))
return imputed_data_x, rmse
if __name__ == '__main__':
# Inputs for the main function
parser = argparse.ArgumentParser()
parser.add_argument(
'--data_name',
choices=['letter','spam'],
default='spam',
type=str)
parser.add_argument(
'--miss_rate',
help='missing data probability',
default=0.2,
type=float)
parser.add_argument(
'--batch_size',
help='the number of samples in mini-batch',
default=128,
type=int)
parser.add_argument(
'--hint_rate',
help='hint probability',
default=0.9,
type=float)
parser.add_argument(
'--alpha',
help='hyperparameter',
default=100,
type=float)
parser.add_argument(
'--iterations',
help='number of training interations',
default=10000,
type=int)
args = parser.parse_args()
# Calls main function
imputed_data, rmse = main(args)