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\data.csv')
data = house_data.dropna()

#检验模型参数
# X = data.ix[:,0:5]
# Y = data.ix[:,6]
# fit = smf.OLS(Y,X).fit()
# print(fit.summary())

rng = np.random

learning_rate = 0.3
training_epochs = 1000

training_data = data.ix[0:20,0:6]
training_label = data.ix[0:20,6]
testing_data = data.ix[21:,0:6]
testing_label = data.ix[21:,6]

n_samples = training_data.shape[0]
X = tf.placeholder(tf.float32)
X2 = tf.placeholder(tf.float32)
X3 = tf.placeholder(tf.float32)
X4 = tf.placeholder(tf.float32)
X5 = tf.placeholder(tf.float32)
X6 = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)

w = tf.Variable(rng.randn(),name="weights",dtype=tf.float32)
w2 = tf.Variable(rng.randn(),name="weights",dtype=tf.float32)
w3 = tf.Variable(rng.randn(),name="weights",dtype=tf.float32)
w4 = tf.Variable(rng.randn(),name="weights",dtype=tf.float32)
w5 = tf.Variable(rng.randn(),name="weights",dtype=tf.float32)
w6 = tf.Variable(rng.randn(),name="weights",dtype=tf.float32)
b = tf.Variable(rng.randn(),name="biases",dtype=tf.float32)

pred = tf.multiply(X,w)+tf.multiply(X2,w2)+tf.multiply(X3,w3)+tf.multiply(X4,w4)+tf.multiply(X5,w5)+tf.multiply(X6,w6)+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['longitude'], X2: training_data['latitude'], \
                                      X3: training_data['price'], X4: training_data['buildingTypeId'], \
                                      X5: training_data['tradeTypeId'], X6: training_data['expectedDealPrice'], \
                                      Y: training_label})

    predict_y = sess.run(pred,feed_dict={X: testing_data['longitude'], X2: testing_data['latitude'], \
                                         X3: testing_data['price'], X4: testing_data['buildingTypeId'], \
                                         X5: testing_data['tradeTypeId'], X6: testing_data['expectedDealPrice']})

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

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值