jjzjj

linear-regression

全部标签

Python scikit 学习线性模型参数标准误差

我正在使用sklearn,特别是linear_model模块。在拟合一个简单的线性之后importpandasaspdimportnumpyasnpfromsklearnimportlinear_modelrandn=np.random.randnX=pd.DataFrame(randn(10,3),columns=['X1','X2','X3'])y=pd.DataFrame(randn(10,1),columns=['Y'])model=linear_model.LinearRegression()model.fit(X=X,y=y)我看到了如何通过coef_和intercept_

python - 分析异常 : u"cannot resolve 'name' given input columns: [ list] in sqlContext in spark

我尝试了一个简单的例子:data=sqlContext.read.format("csv").option("header","true").option("inferSchema","true").load("/databricks-datasets/samples/population-vs-price/data_geo.csv")data.cache()#Cachedataforfasterreusedata=data.dropna()#droprowswithmissingvaluesdata=data.select("2014Populationestimate","2015

python - 使用带有 statsmodels 的 OLS 模型预测值

我使用OLS(多元线性回归)计算了一个模型。我将我的数据划分为训练和测试(各一半),然后我想预测第二部分标签的值。model=OLS(labels[:half],data[:half])predictions=model.predict(data[half:])问题是我得到了错误:文件“/usr/local/lib/python2.7/dist-packages/statsmodels-0.5.0-py2.7-linux-i686.egg/statsmodels/regression/linear_model.py”,第281行,预测返回np.dot(exog,参数)ValueErro

python - 增加线性回归的成本

出于训练目的,我在python中实现了线性回归。问题是成本在增加而不是减少。对于数据,我使用机翼自噪声数据集。资料可查here我按如下方式导入数据:importpandasaspddeffeatures():features=pd.read_csv("data/airfoil_self_noise/airfoil_self_noise.dat.txt",sep="\t",header=None)X=features.iloc[:,0:5]Y=features.iloc[:,5]returnX.values,Y.values.reshape(Y.shape[0],1)我的线性回归代码如下

python - python中用于计算最小范数解或从伪逆获得的解的最准确方法是什么?

我的目标是解决:Kc=y对于伪逆(即最小范数解):c=K^{+}y这样的模型(希望)是高次多项式模型。我特别感兴趣的是未确定的情况,在这种情况下,我们有比数据更多的多项式特征(很少有方程太多变量/未知量)f(x)=sum_ic_ix^i。注:columns=deg+1>N=rows是多项式特征的范德模式矩阵。我最初使用的是python函数np.linalg.pinv,但后来我注意到了一些奇怪的事情正在发生,正如我在这里注意到的那样:WhydodifferentmethodsforsolvingXc=yinpythongivedifferentsolutionwhentheyshould

python - python中用于计算最小范数解或从伪逆获得的解的最准确方法是什么?

我的目标是解决:Kc=y对于伪逆(即最小范数解):c=K^{+}y这样的模型(希望)是高次多项式模型。我特别感兴趣的是未确定的情况,在这种情况下,我们有比数据更多的多项式特征(很少有方程太多变量/未知量)f(x)=sum_ic_ix^i。注:columns=deg+1>N=rows是多项式特征的范德模式矩阵。我最初使用的是python函数np.linalg.pinv,但后来我注意到了一些奇怪的事情正在发生,正如我在这里注意到的那样:WhydodifferentmethodsforsolvingXc=yinpythongivedifferentsolutionwhentheyshould

python - Python 中的高效协整检验

我想知道是否有比以下方法更好的方法来测试两个变量是否协整:importnumpyasnpimportstatsmodels.apiassmimportstatsmodels.tsa.stattoolsastsy=np.random.normal(0,1,250)x=np.random.normal(0,1,250)defcointegration_test(y,x):#Step1:regressonvariableontheotherols_result=sm.OLS(y,x).fit()#Step2:obtaintheresidual(ols_resuld.resid)#Step3:

python - Python 中的高效协整检验

我想知道是否有比以下方法更好的方法来测试两个变量是否协整:importnumpyasnpimportstatsmodels.apiassmimportstatsmodels.tsa.stattoolsastsy=np.random.normal(0,1,250)x=np.random.normal(0,1,250)defcointegration_test(y,x):#Step1:regressonvariableontheotherols_result=sm.OLS(y,x).fit()#Step2:obtaintheresidual(ols_resuld.resid)#Step3:

python - sklearn中的LinearRegression方法中,fit_intercept参数到底是干什么用的?

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎与helpcenter中定义的范围内的编程无关。.关闭2年前。Improvethisquestion在sklearn.linear_model.LinearRegression方法中,有一个参数是fit_intercept=TRUE或fit_intercept=FALSE。我想知道如果我们将它设置为TRUE,它是否会向您的数据集添加一个全1的附加截距列?如果我已经有一个包含一列1的数据集,fit_intercept=FALSE是否说明了这一点,还是强制它拟合零截距模型?更新:似乎人们没有理

python - sklearn中的LinearRegression方法中,fit_intercept参数到底是干什么用的?

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎与helpcenter中定义的范围内的编程无关。.关闭2年前。Improvethisquestion在sklearn.linear_model.LinearRegression方法中,有一个参数是fit_intercept=TRUE或fit_intercept=FALSE。我想知道如果我们将它设置为TRUE,它是否会向您的数据集添加一个全1的附加截距列?如果我已经有一个包含一列1的数据集,fit_intercept=FALSE是否说明了这一点,还是强制它拟合零截距模型?更新:似乎人们没有理