1# Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Multi-output tests.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21import random 22 23import numpy as np 24 25from tensorflow.contrib.learn.python import learn 26from tensorflow.contrib.learn.python.learn.estimators._sklearn import mean_squared_error 27from tensorflow.python.platform import test 28 29 30class MultiOutputTest(test.TestCase): 31 """Multi-output tests.""" 32 33 def testMultiRegression(self): 34 random.seed(42) 35 rng = np.random.RandomState(1) 36 x = np.sort(200 * rng.rand(100, 1) - 100, axis=0) 37 y = np.array([np.pi * np.sin(x).ravel(), np.pi * np.cos(x).ravel()]).T 38 regressor = learn.LinearRegressor( 39 feature_columns=learn.infer_real_valued_columns_from_input(x), 40 label_dimension=2) 41 regressor.fit(x, y, steps=100) 42 score = mean_squared_error(np.array(list(regressor.predict_scores(x))), y) 43 self.assertLess(score, 10, "Failed with score = {0}".format(score)) 44 45 46if __name__ == "__main__": 47 test.main() 48