Skip to content

Commit 8ff0572

Browse files
authored
Merge pull request #41 from lienhua34/dist-base
提供支持 contrib.learn 的开发环境
2 parents a8bdae8 + d98427f commit 8ff0572

File tree

17 files changed

+826
-33
lines changed

17 files changed

+826
-33
lines changed

caicloud.tensorflow/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.4
1+
2.1.0

caicloud.tensorflow/caicloud/clever/examples/boston_house/__init__.py

Whitespace-only changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
5+
import itertools
6+
7+
import pandas as pd
8+
import tensorflow as tf
9+
import tensorflow.contrib.learn as learn
10+
11+
from caicloud.clever.tensorflow import dist_base
12+
from caicloud.clever.tensorflow import model_exporter
13+
14+
tf.app.flags.DEFINE_string("data_dir",
15+
".",
16+
"data directory path.")
17+
tf.app.flags.DEFINE_string("export_dir",
18+
None,
19+
"model export directory path.")
20+
FLAGS = tf.app.flags.FLAGS
21+
22+
tf.logging.set_verbosity(tf.logging.INFO)
23+
24+
COLUMNS = ["crim", "zn", "indus", "nox", "rm", "age",
25+
"dis", "tax", "ptratio", "medv"]
26+
FEATURES = ["crim", "zn", "indus", "nox", "rm",
27+
"age", "dis", "tax", "ptratio"]
28+
LABEL = "medv"
29+
30+
training_set = pd.read_csv("{0}/boston_train.csv".format(FLAGS.data_dir),
31+
skipinitialspace=True,
32+
skiprows=1, names=COLUMNS)
33+
test_set = pd.read_csv("{0}/boston_test.csv".format(FLAGS.data_dir),
34+
skipinitialspace=True,
35+
skiprows=1, names=COLUMNS)
36+
37+
feature_cols = [tf.contrib.layers.real_valued_column(k)
38+
for k in FEATURES]
39+
40+
run_config = tf.contrib.learn.RunConfig(
41+
save_checkpoints_secs=dist_base.cfg.save_checkpoints_secs)
42+
regressor = tf.contrib.learn.DNNRegressor(
43+
feature_columns=feature_cols,
44+
hidden_units=[10, 10],
45+
model_dir=dist_base.cfg.logdir,
46+
config=run_config)
47+
48+
_input_tensors = None
49+
_output_tensor = None
50+
def input_fn():
51+
global _input_tensors, _output_tensor
52+
_input_tensors = {k: tf.placeholder(dtype=tf.float64, shape=[None], name=k)
53+
for k in FEATURES}
54+
_output_tensor = tf.placeholder(dtype=tf.float64, shape=[None], name=LABEL)
55+
return _input_tensors, _output_tensor
56+
57+
def feed_fn(data_set):
58+
global _input_tensors, _output_tensor
59+
feed_dict = {_input_tensors[k]: data_set[k].values
60+
for k in FEATURES}
61+
feed_dict[_output_tensor] = data_set[LABEL].values
62+
return feed_dict
63+
64+
train_monitors = [tf.train.FeedFnHook(lambda: feed_fn(training_set))]
65+
eval_hooks = [tf.train.FeedFnHook(lambda: feed_fn(test_set))]
66+
model_export_spec = None
67+
if FLAGS.export_dir is not None:
68+
model_export_spec = model_exporter.ModelExportSpec(
69+
export_dir=FLAGS.export_dir,
70+
features=feature_cols)
71+
exp = dist_base.Experiment(
72+
estimator = regressor,
73+
train_input_fn = input_fn,
74+
eval_input_fn = input_fn,
75+
train_monitors = train_monitors,
76+
eval_hooks = eval_hooks,
77+
eval_steps = 1,
78+
model_export_spec = model_export_spec)
79+
80+
exp.run()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6,9,CRIM,ZN,INDUS,NOX,RM,AGE,DIS,TAX,PTRATIO
2+
0.03359,75.0,2.95,0.428,7.024,15.8,5.4011,252,18.3
3+
5.09017,0.0,18.1,0.713,6.297,91.8,2.3682,666,20.2
4+
0.1265,25.0,5.13,0.453,6.762,43.4,7.9809,284,19.7
5+
0.05515,33.0,2.18,0.472,7.236,41.1,4.022,222,18.4
6+
8.15174,0.0,18.1,0.7,5.39,98.9,1.7281,666,20.2
7+
0.24522,0.0,9.9,0.544,5.782,71.7,4.0317,304,18.4
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
100,9,CRIM,ZN,INDUS,NOX,RM,AGE,DIS,TAX,PTRATIO,MEDV
2+
0.13587,0.0,10.59,0.489,6.064,59.1,4.2392,277,18.6,24.4
3+
0.08664,45.0,3.44,0.437,7.178,26.3,6.4798,398,15.2,36.4
4+
0.26938,0.0,9.9,0.544,6.266,82.8,3.2628,304,18.4,21.6
5+
0.05302,0.0,3.41,0.489,7.079,63.1,3.4145,270,17.8,28.7
6+
0.0686,0.0,2.89,0.445,7.416,62.5,3.4952,276,18.0,33.2
7+
0.14231,0.0,10.01,0.547,6.254,84.2,2.2565,432,17.8,18.5
8+
0.1676,0.0,7.38,0.493,6.426,52.3,4.5404,287,19.6,23.8
9+
0.04301,80.0,1.91,0.413,5.663,21.9,10.5857,334,22.0,18.2
10+
0.06905,0.0,2.18,0.458,7.147,54.2,6.0622,222,18.7,36.2
11+
0.21719,0.0,10.59,0.489,5.807,53.8,3.6526,277,18.6,22.4
12+
0.06076,0.0,11.93,0.573,6.976,91.0,2.1675,273,21.0,23.9
13+
4.03841,0.0,18.1,0.532,6.229,90.7,3.0993,666,20.2,19.6
14+
0.16902,0.0,25.65,0.581,5.986,88.4,1.9929,188,19.1,21.4
15+
0.52693,0.0,6.2,0.504,8.725,83.0,2.8944,307,17.4,50.0
16+
12.0482,0.0,18.1,0.614,5.648,87.6,1.9512,666,20.2,20.8
17+
3.1636,0.0,18.1,0.655,5.759,48.2,3.0665,666,20.2,19.9
18+
0.10008,0.0,2.46,0.488,6.563,95.6,2.847,193,17.8,32.5
19+
2.15505,0.0,19.58,0.871,5.628,100.0,1.5166,403,14.7,15.6
20+
0.03584,80.0,3.37,0.398,6.29,17.8,6.6115,337,16.1,23.5
21+
0.13554,12.5,6.07,0.409,5.594,36.8,6.498,345,18.9,17.4
22+
17.8667,0.0,18.1,0.671,6.223,100.0,1.3861,666,20.2,10.2
23+
0.09378,12.5,7.87,0.524,5.889,39.0,5.4509,311,15.2,21.7
24+
0.05372,0.0,13.92,0.437,6.549,51.0,5.9604,289,16.0,27.1
25+
9.96654,0.0,18.1,0.74,6.485,100.0,1.9784,666,20.2,15.4
26+
3.8497,0.0,18.1,0.77,6.395,91.0,2.5052,666,20.2,21.7
27+
0.47547,0.0,9.9,0.544,6.113,58.8,4.0019,304,18.4,21.0
28+
0.06642,0.0,4.05,0.51,6.86,74.4,2.9153,296,16.6,29.9
29+
0.04011,80.0,1.52,0.404,7.287,34.1,7.309,329,12.6,33.3
30+
0.40202,0.0,9.9,0.544,6.382,67.2,3.5325,304,18.4,23.1
31+
0.04527,0.0,11.93,0.573,6.12,76.7,2.2875,273,21.0,20.6
32+
0.06617,0.0,3.24,0.46,5.868,25.8,5.2146,430,16.9,19.3
33+
0.06417,0.0,5.96,0.499,5.933,68.2,3.3603,279,19.2,18.9
34+
0.09068,45.0,3.44,0.437,6.951,21.5,6.4798,398,15.2,37.0
35+
0.10469,40.0,6.41,0.447,7.267,49.0,4.7872,254,17.6,33.2
36+
0.36894,22.0,5.86,0.431,8.259,8.4,8.9067,330,19.1,42.8
37+
0.17134,0.0,10.01,0.547,5.928,88.2,2.4631,432,17.8,18.3
38+
0.77299,0.0,8.14,0.538,6.495,94.4,4.4547,307,21.0,18.4
39+
0.5405,20.0,3.97,0.575,7.47,52.6,2.872,264,13.0,43.5
40+
0.1396,0.0,8.56,0.52,6.167,90.0,2.421,384,20.9,20.1
41+
0.76162,20.0,3.97,0.647,5.56,62.8,1.9865,264,13.0,22.8
42+
0.09065,20.0,6.96,0.464,5.92,61.5,3.9175,223,18.6,20.7
43+
0.13117,0.0,8.56,0.52,6.127,85.2,2.1224,384,20.9,20.4
44+
0.43571,0.0,10.59,0.489,5.344,100.0,3.875,277,18.6,20.0
45+
1.41385,0.0,19.58,0.871,6.129,96.0,1.7494,403,14.7,17.0
46+
11.8123,0.0,18.1,0.718,6.824,76.5,1.794,666,20.2,8.4
47+
7.02259,0.0,18.1,0.718,6.006,95.3,1.8746,666,20.2,14.2
48+
4.26131,0.0,18.1,0.77,6.112,81.3,2.5091,666,20.2,22.6
49+
2.3139,0.0,19.58,0.605,5.88,97.3,2.3887,403,14.7,19.1
50+
0.62739,0.0,8.14,0.538,5.834,56.5,4.4986,307,21.0,19.9
51+
0.11747,12.5,7.87,0.524,6.009,82.9,6.2267,311,15.2,18.9
52+
22.5971,0.0,18.1,0.7,5.0,89.5,1.5184,666,20.2,7.4
53+
4.22239,0.0,18.1,0.77,5.803,89.0,1.9047,666,20.2,16.8
54+
0.03548,80.0,3.64,0.392,5.876,19.1,9.2203,315,16.4,20.9
55+
0.08199,0.0,13.92,0.437,6.009,42.3,5.5027,289,16.0,21.7
56+
0.11432,0.0,8.56,0.52,6.781,71.3,2.8561,384,20.9,26.5
57+
1.34284,0.0,19.58,0.605,6.066,100.0,1.7573,403,14.7,24.3
58+
12.2472,0.0,18.1,0.584,5.837,59.7,1.9976,666,20.2,10.2
59+
0.21977,0.0,6.91,0.448,5.602,62.0,6.0877,233,17.9,19.4
60+
0.01096,55.0,2.25,0.389,6.453,31.9,7.3073,300,15.3,22.0
61+
0.12816,12.5,6.07,0.409,5.885,33.0,6.498,345,18.9,20.9
62+
0.17004,12.5,7.87,0.524,6.004,85.9,6.5921,311,15.2,18.9
63+
2.63548,0.0,9.9,0.544,4.973,37.8,2.5194,304,18.4,16.1
64+
0.21409,22.0,5.86,0.431,6.438,8.9,7.3967,330,19.1,24.8
65+
0.04417,70.0,2.24,0.4,6.871,47.4,7.8278,358,14.8,24.8
66+
0.75026,0.0,8.14,0.538,5.924,94.1,4.3996,307,21.0,15.6
67+
13.6781,0.0,18.1,0.74,5.935,87.9,1.8206,666,20.2,8.4
68+
0.09604,40.0,6.41,0.447,6.854,42.8,4.2673,254,17.6,32.0
69+
0.1403,22.0,5.86,0.431,6.487,13.0,7.3967,330,19.1,24.4
70+
0.44178,0.0,6.2,0.504,6.552,21.4,3.3751,307,17.4,31.5
71+
0.03445,82.5,2.03,0.415,6.162,38.4,6.27,348,14.7,24.1
72+
0.10084,0.0,10.01,0.547,6.715,81.6,2.6775,432,17.8,22.8
73+
0.08707,0.0,12.83,0.437,6.14,45.8,4.0905,398,18.7,20.8
74+
0.35114,0.0,7.38,0.493,6.041,49.9,4.7211,287,19.6,20.4
75+
0.11027,25.0,5.13,0.453,6.456,67.8,7.2255,284,19.7,22.2
76+
0.01501,80.0,2.01,0.435,6.635,29.7,8.344,280,17.0,24.5
77+
9.51363,0.0,18.1,0.713,6.728,94.1,2.4961,666,20.2,14.9
78+
0.07503,33.0,2.18,0.472,7.42,71.9,3.0992,222,18.4,33.4
79+
11.1604,0.0,18.1,0.74,6.629,94.6,2.1247,666,20.2,13.4
80+
7.52601,0.0,18.1,0.713,6.417,98.3,2.185,666,20.2,13.0
81+
2.73397,0.0,19.58,0.871,5.597,94.9,1.5257,403,14.7,15.4
82+
0.2909,0.0,21.89,0.624,6.174,93.6,1.6119,437,21.2,14.0
83+
9.33889,0.0,18.1,0.679,6.38,95.6,1.9682,666,20.2,9.5
84+
0.02498,0.0,1.89,0.518,6.54,59.7,6.2669,422,15.9,16.5
85+
0.12269,0.0,6.91,0.448,6.069,40.0,5.7209,233,17.9,21.2
86+
0.10959,0.0,11.93,0.573,6.794,89.3,2.3889,273,21.0,22.0
87+
0.08014,0.0,5.96,0.499,5.85,41.5,3.9342,279,19.2,21.0
88+
0.03113,0.0,4.39,0.442,6.014,48.5,8.0136,352,18.8,17.5
89+
5.82115,0.0,18.1,0.713,6.513,89.9,2.8016,666,20.2,20.2
90+
0.65665,20.0,3.97,0.647,6.842,100.0,2.0107,264,13.0,30.1
91+
0.79041,0.0,9.9,0.544,6.122,52.8,2.6403,304,18.4,22.1
92+
0.09266,34.0,6.09,0.433,6.495,18.4,5.4917,329,16.1,26.4
93+
0.17783,0.0,9.69,0.585,5.569,73.5,2.3999,391,19.2,17.5
94+
0.07013,0.0,13.89,0.55,6.642,85.1,3.4211,276,16.4,28.7
95+
0.41238,0.0,6.2,0.504,7.163,79.9,3.2157,307,17.4,31.6
96+
15.5757,0.0,18.1,0.58,5.926,71.0,2.9084,666,20.2,19.1
97+
0.13262,0.0,8.56,0.52,5.851,96.7,2.1069,384,20.9,19.5
98+
6.80117,0.0,18.1,0.713,6.081,84.4,2.7175,666,20.2,20.0
99+
12.8023,0.0,18.1,0.74,5.854,96.6,1.8956,666,20.2,10.8
100+
10.233,0.0,18.1,0.614,6.185,96.7,2.1705,666,20.2,14.6
101+
0.35809,0.0,6.2,0.507,6.951,88.5,2.8617,307,17.4,26.7

0 commit comments

Comments
 (0)