Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tensorflow是否支持在线培训?_Python_Tensorflow_Linear Regression - Fatal编程技术网

Python tensorflow是否支持在线培训?

Python tensorflow是否支持在线培训?,python,tensorflow,linear-regression,Python,Tensorflow,Linear Regression,我试图一个样本一个样本地提供数据。在不同的数据集上,结果要么完全错误,要么非常近似(25-50%绝对误差)。如果一次性训练,所有数据集的结果都很好 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 se

我试图一个样本一个样本地提供数据。在不同的数据集上,结果要么完全错误,要么非常近似(25-50%绝对误差)。如果一次性训练,所有数据集的结果都很好

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.S.
fit
partial\u fit
根据来源是相同的

这看起来像是学习率和/或优化。请按以下方式尝试:


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

你的意思是你有将其用于在线培训的成功经验吗?