TensorFlow多元回归预测房子滞留天数

# -*- coding: utf-8 -*-

import pandas as pd
import numpy as np
import statsmodels.formula.api as smf
import tensorflow as tf
import matplotlib.pyplot as plt

house_data = pd.read_csv('F:\lcl\data1.csv').astype(np.float32)

data = house_data.dropna()

learning_rate = 0.3
training_epochs = 1000

training_data = data.ix[0:20,0:6]
training_data = np.asarray(training_data).reshape(21,6)

training_label = data.ix[0:20,6]
training_label = np.asarray(training_label).reshape(21,1)

testing_data = data.ix[21:,0:6]
testing_data = np.asarray(testing_data).reshape(7,6)
testing_label = data.ix[21:,6]
testing_label = np.asarray(testing_label).reshape(7,1)

n_samples = training_data.shape[0]
X = tf.placeholder(tf.float32,[None,6])
Y = tf.placeholder(tf.float32,[None,1])

w = tf.Variable(tf.random_uniform((6,1),-1.0,1.0),name="weights",dtype=tf.float32)
b = tf.Variable(tf.random_uniform((1,1)),name="biases",dtype=tf.float32)


pred = tf.add(tf.matmul(X,w),b)
cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples)

#优化器
optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost)

init = tf.global_variables_initializer()

with tf.Session() as sess:

    sess.run(init)

    for epoch in range(training_epochs):

        sess.run(optimizer,feed_dict={X: training_data,Y: training_label})

    predict_y = sess.run(pred, feed_dict={X: testing_data})

    print(predict_y)
    mse = tf.reduce_mean(tf.square((predict_y - testing_label)))
    print("MSE: %.4f" % sess.run(mse))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值