Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于线性模型,Python与R预测函数的等价性是什么?_Python_R_Scipy_Linear Regression_Prediction - Fatal编程技术网

对于线性模型,Python与R预测函数的等价性是什么?

对于线性模型,Python与R预测函数的等价性是什么?,python,r,scipy,linear-regression,prediction,Python,R,Scipy,Linear Regression,Prediction,对于线性模型,Python与R预测函数的等价性是什么 我确信scipy中有一些东西可以在这里提供帮助,但是是否有一个等价的函数 Scipy有很多回归工具和预测方法;尽管在IMO中,Pandas是最接近于复制R功能的python库,包括predict方法。以下R和python中的代码片段演示了这些相似之处 R线性回归: data(trees) linmodel <- lm(Volume~., data = trees[1:20,]) linpred <- predict(linmode

对于线性模型,Python与R预测函数的等价性是什么

我确信scipy中有一些东西可以在这里提供帮助,但是是否有一个等价的函数

Scipy有很多回归工具和预测方法;尽管在IMO中,Pandas是最接近于复制R功能的python库,包括predict方法。以下R和python中的代码片段演示了这些相似之处

R线性回归:

data(trees)
linmodel <- lm(Volume~., data = trees[1:20,])
linpred <- predict(linmodel, trees[21:31,])
plot(linpred, trees$Volume[21:31])

您可能需要检查
statsmodels
scikit learn
以了解线性模型的实现。如前所述,您还可以尝试scipy.stats.linregresse
import pandas as pd
from pandas.stats.api import ols
import matplotlib.pyplot as plt

trees = pd.read_csv('trees.csv')
linmodel = ols(y = trees['Volume'][0:20], x = trees[['Girth', 'Height']][0:20])
linpred = linmodel.predict(x = trees[['Girth', 'Height']][20:31])
plt.scatter(linpred,trees['Volume'][20:31])