python - 如何在 Python 中进行多元回归分析?

标签 python tensorflow regression

我根据以下假设运行以下简单代码:

A值和B值相似,通过组合多个变量使B值等于A值。

所以我的假设是这样的

A = W1(权重)*B + W2(权重)C(另一个变量)+...

这是我的尝试代码

hypothesis = tf.sigmoid(tf.matmul(X1, W1)+tf.matmul(X2, W2)+tf.matmul(X3, W3)+tf.matmul(X4, W4) + tf.matmul(X5, W5) + b1)


cost = -tf.reduce_mean(Y * tf.log(hypothesis) + (1 - Y) * tf.log(1 - hypothesis))
train = tf.train.GradientDescentOptimizer(learning_rate=0.000000000000000001).minimize(cost)

predicted = tf.cast(hypothesis > 0.5, dtype=tf.float32)
accuracy = tf.reduce_mean(tf.cast(tf.equal(predicted, Y), dtype=tf.float32))

with tf.Session() as sess:
   # Initialize TensorFlow variables
   sess.run(tf.global_variables_initializer())
   for step in range(5000):
       sess.run(y, feed_dict={X1:ct, X2: temperature, X3:humidity, X4: windspeed, X5:tideheight, Y:sst})

但是,当我验证此代码的值时,我得出了一个根本不合适的值。

当我查看数据集时,它似乎不是线性的。

如果您能为我提供有关这种情况的示例,我将不胜感激。

我的数据集:

 A         B             C              D         E       F
25.6    27.29999    24.4752741667   71.5801495  6.468   97.1
25.6    27.5    24.3449186667   71.1314193333   5.39    288.3
25.4    27.60001    24.4019961667   71.8209758333   6.076   103.7
25.5    27.5    24.3473485  71.3570816667   6.762   95.3
25.5    27.5    24.3420308333   71.9577738333   5.978   103.7
25.6    27.29999    24.464413   71.993804   6.37    105.8
25.6    27.29999    24.3999401667   71.5558695  6.664   100.2
                           ...

最佳答案

我不确定神经网络是否是解决此类问题的正确选择。我建议用线性回归来解决它。我宁愿开始熟悉 scikit-learn 库 及其用于监督学习的算法。 http://scikit-learn.org/stable/supervised_learning.html#supervised-learning Pandas https://pandas.pydata.org/以便于进行数据预处理。 在您对库有了更多的熟悉之后,请尝试遵循以下策略:

  1. 对数据集进行预处理(即删除nans,不必要的 列,扩展您的功能)
  2. 将数据集拆分为训练数据集 和测试零件。
  3. 尝试运行多个线性模型(即 LinearRegression、Ridge),也尝试改进的验证方案 (KFold、分层KFold)
  4. 选择适当的指标来验证您的模型

Scikit 学习文档应该包含所有 必要的信息。祝你好运

关于python - 如何在 Python 中进行多元回归分析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50924132/

相关文章:

python-3.x - TensorFlow - 简单前馈神经网络未训练

matlab - 交叉验证matlab - crossval函数

python - pd.equals() 在将数据帧转换为 CSV 并返回数据帧后返回 false

python - Instagram 抓取

python - 何时使用 tensorflow 估计器?

c++ - 可以在QT项目中使用Tensorflow C++ API吗?

python - 检测折线图分段的正确算法是什么?

r - Predict.glm(..., type = "response", se.fit = TRUE) 返回什么标准错误?

python - 在 Pandas 的整个列中计算字符串的出现次数

python - 贝叶斯网络针对特定应用的pythonic实现