2017-01-24 2 views
0

私はデータをサンプルごとにフィードしようとします。結果は、異なるデータセットでは完全に間違っているか、または非常に近似しています(絶対エラーの25〜50%)。 1つのトレーニングであれば、結果はすべてのデータセットで問題ありません。テンソルフローはオンライントレーニングをサポートしていますか?

import itertools as itools 
import numpy as np 
import tensorflow as tf 
from sklearn import preprocessing 

class Test: 
    def __init__(self, x, y): 
     self.x = x 
     self.y = y 
     self._i = 0 

    def do_test(self): 
     x_col = tf.contrib.layers.real_valued_column("x", dimension=1) 
     model = tf.contrib.learn.LinearRegressor(feature_columns=[x_col]) 
     print("Fitting") 
     max_steps = 80 
     for _ in range(0, len(self.x)): 
      model.fit(input_fn=self.input_split, steps=max_steps) 
     print("Predicting") 
     scaled_out = model.predict(input_fn=self.eval_fn) 
     print(self._inverse_y(list(itools.islice(scaled_out, self.eval_len)))) 

    def input_split(self): 
     if 0 == self._i: 
      self.x_std, self.y_std = self._transform(self.x, self.y) 
     if len(self.x_std) == self._i: 
      raise StopIteration 
     x = self.x_std[self._i] 
     y = self.y_std[self._i] 
     self._i += 1 
     feature_cols = {"x": tf.constant([x], dtype=tf.float32), 
         } 
     print(x, y) 
     label = tf.constant([y], dtype=tf.float32) 
     return feature_cols, label 

    def eval_fn(self): 
     x = [0, 1, 5, 10] 
     y = np.zeros(len(x)) 

     self.eval_len = len(x) 

     x_std, y_std = self._transform(x, y) 
     feature_cols = {"x": tf.constant(x_std, dtype=tf.float32), 
       } 
     label = tf.constant(y_std, dtype=tf.float32) 
     return feature_cols, label 


    def _transform(self, x_in, y_in): 
     if not hasattr(self, "x_scaler"): 
      self.x_scaler = preprocessing.StandardScaler().fit(x_in) 
      self.y_scaler = preprocessing.StandardScaler().fit(y_in) 
     x_std = self.x_scaler.transform(x_in) 
     y_std = self.y_scaler.transform(y_in) 
     return x_std, y_std 

    def _inverse_y(self, y_std): 
     return self.y_scaler.inverse_transform(y_std) 

P. fitpartial_fitはソースに応じて同じです

答えて

1

これはlearning_rateや最適化のようです。次のように彼らとしてみてください:

model = tf.contrib.learn.LinearRegressor(..., optimizer=tf.train.YOUR_OPTIMIZER(YOUR_LEARNING_RATE)))

+0

あなたがオンライントレーニングのためにそれを使用して成功した経験を持っていたわけですか? – VladimirLenin

関連する問題