1
与线性模型的R预测函数等价的Python是什么?什么是相当于线性模型的R预测函数的Python?
我敢肯定在scipy中有一些东西可以在这里帮助,但是有没有相同的功能?
https://stat.ethz.ch/R-manual/R-patched/library/stats/html/predict.lm.html
与线性模型的R预测函数等价的Python是什么?什么是相当于线性模型的R预测函数的Python?
我敢肯定在scipy中有一些东西可以在这里帮助,但是有没有相同的功能?
https://stat.ethz.ch/R-manual/R-patched/library/stats/html/predict.lm.html
SciPy的有回归工具大量,虽然很多都没有在很好地包裹泛型方法将R风格。 Pandas是最接近复制R功能的python库,完成了预测方法。 R和python中的以下片段展示了相似之处。
[R线性回归:
data(trees)
linmodel <- lm(Volume~., data = trees[1:20,])
linpred <- predict(linmodel, trees[21:31,])
plot(linpred, trees$Volume[21:31])
相同的数据使用熊猫ols
在python设置:
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])
您可能要检查'statsmodels'和'scikit-learn'线性模型的实现。 – cel 2015-03-13 15:37:25