【问题标题】:How to get predicted values (independent variable) for each observation in Matlab?如何在 Matlab 中获取每个观察值的预测值(自变量)?
【发布时间】:2014-06-28 06:12:54
【问题描述】:

我在 Matlab 中进行了回归并得到了正常结果(系数等)。我想问一下,我现在如何为我的数据集中的每个观察值计算这个模型的预测值(自变量),然后将值直接保存到文件中?

感谢您的帮助。

【问题讨论】:

  • 如果你运行回归,你应该有一个封闭形式的模型来解释它的行为(在一定的容错范围内)。你不能只将观察/独立值替换到你的模型中吗?你能给我们更多的信息吗?你的模型是什么样的?你的代码是什么样的?

标签: matlab statistics


【解决方案1】:

如果你有一些任意的函数来拟合你的数据,那么你可以像这样编写一个单独的函数:

function y_pred = calcy(coeffs,xvals)
%%//coeffs is a vector of the fitted coefficients, x is a vector
%%//Calculate the predicted values here using whatever model you're using and the fitted
%%//coefficients and x-values

end

在你的主函数中你会调用:

y_pred = calcy(coeffs,xvals);
dlmwrite('file.txt',y_pred);

这将以逗号分隔的格式将向量写入您的目录。您可以查看 dlmwrite 的文档以了解如何更改格式以满足您的需求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-27
    • 2013-12-03
    • 1970-01-01
    • 2012-02-09
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多