Skip to content

Commit

Permalink
linear model with NAL data kristoferB/SP#86
Browse files Browse the repository at this point in the history
  • Loading branch information
edvardlindelof committed Jul 16, 2017
1 parent 3ba283c commit 27c8616
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
3 changes: 3 additions & 0 deletions models/linear/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NALState2017-07-11T15:14:43.994+02:00.csv
modeldir/
exportedmodel/
Empty file added models/linear/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions models/linear/train_and_export_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import tensorflow as tf
from tensorflow.contrib.learn import LinearRegressor
from tensorflow.contrib import layers
from tensorflow.contrib.learn.python.learn.utils import input_fn_utils
tf.logging.set_verbosity(tf.logging.INFO)

import pandas as pd

FEATURES = ["ttt30", "all", "MEP", "triaged", "PRIO3", "PRIO4"]

pdframe = pd.read_csv("NALState2017-07-11T15:14:43.994+02:00.csv")

def input_fn_train():
feature_cols = {name: tf.constant(pdframe[name].get_values()[:-1]) for name in FEATURES}
# TODO atm predicting next ttt30 when sample intervals are 23 min..
outputs = tf.constant(pdframe["ttt30"].get_values()[1:])
return feature_cols, outputs

feature_cols = [layers.real_valued_column(name) for name in FEATURES]
regressor = LinearRegressor(
feature_columns=feature_cols,
model_dir="./modeldir"
)
regressor.fit(input_fn=input_fn_train, steps=10000)

'''
def serving_input_fn():
default_inputs = {col.name: tf.placeholder(col.dtype, [None]) for col in feature_cols}
features = {key: tf.expand_dims(tensor, -1) for key, tensor in default_inputs.items()}
return input_fn_utils.InputFnOps(
features=features,
labels=None,
default_inputs=default_inputs
)
regressor.export_savedmodel(
"exportedmodel",
serving_input_fn
)
'''
17 changes: 0 additions & 17 deletions models/test_pandas.py

This file was deleted.

0 comments on commit 27c8616

Please sign in to comment.