Tensorflow基于神经网络进行多元变量回归分析

#引入相关库
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from sklearn import preprocessing


#读取数据
train_data=np.array(pd.read_csv("train.txt"))
test_data=np.array(pd.read_csv("test.txt"))

#提取特征列,即X (共18列,代表18个变量)
train_feature=np.array(train_data[:,[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]])
#提取预测结果列,即Y
train_label=np.array(train_data[:,[18]])
#提取测试集特征列
test_x=np.array(test_data[:,[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]])
print(test_data.shape)

#搭建神经网络
#定义x y
x = tf.placeholder(tf.float32,[None,18])  #长度为18,代表18个特征
y = tf.placeholder(tf.float32,[None,1])   #长度为1,代表要预测的变量只有1个
train_feature=preprocessing.scale(train_feature)  #数据预处理,归一化
test_xs=preprocessing.scale(test_x)    #也对测试集进行预处理
print(test_xs.shape)

#定义神经网络隐藏层

#初始化权值。 为18*20矩阵  20代表20个神经元
Weights_L1 = tf.Variable(tf.random_normal([18,20
  • 11
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值