如何在Python statmodels中创建MLR文件 [英] How to create MLR file in Python statmodels
问题描述
创建文件
Python Statsmodels中的MLR
运行以下代码以加载所需的库并创建数据集以适合模型。
导入pandas为pd
来自sklearn.datasets import load_boston
boston = load_boston()
dataset = pd.DataFrame(boston.data,columns = boston.feature_names)
数据集['target'] = boston.target
我必须执行以下步骤来完成此hands_on场景。
1.执行波士顿住房数据的多元回归。
2.适当导入statsmodels包在你的代码中。
3.使用目标变量作为因变量。
4.使用剩下的变量作为自变量。
5.使用statsmodels包创建一个多元回归模型。
6.Wh at是所有变量的相关值。
7.估算系数的值是多少?
8.每个变量的重要值是什么?
9.最后在代码中打印模型摘要。
您可以使用vim app.py编写代码。
按i进行插入模式。
按esc然后:wq保存并退出编辑器。
我尝试过:
create file
MLR in Python Statsmodels
Run the following code to load the required libraries and create the data set to fit the model.
import pandas as pd
from sklearn.datasets import load_boston
boston = load_boston()
dataset = pd.DataFrame(boston.data, columns=boston.feature_names)
dataset['target'] = boston.target
I have to perform the following steps to complete this hands_on scenarios.
1.Perform Multiple regression on Boston Housing Data .
2.Import statsmodels packages appropriately in your code.
3.Use the Target Variable as the Dependent Variable.
4.Use the remaining variables as the independent variable.
5.Fit a multiple regression model using statsmodels package.
6.What are the correlation values for all the variables.
7.What are the values of the estimated coefficients ?
8.What is the significance value of each variable ?
9.Finally print the model summary in your code.
You can write your code using vim app.py .
Press i for insert mode.
Press esc and then :wq to save and quit the editor.
What I have tried:
import pandas as pd
from sklearn.datasets import load_boston
boston = load_boston()
dataset = pd.DataFrame(boston.data, columns=boston.feature_names)
dataset['target'] = boston.target
推荐答案
python statmodels - Google搜索 [ ^ ]
尝试使用以下解决方案。
它对我有用
Try the Below Solution.
It worked for me
from sklearn.datasets import load_boston
from sklearn import linear_model
import pandas as pd
boston = load_boston()
dataset = pd.DataFrame(boston.data, columns=boston.feature_names)
dataset['target'] = boston.target
print(dataset.head())
import statsmodels.api as sm
import statsmodels.formula.api as smf
X = dataset.drop('target', axis = 1)
y = dataset['target']
X = sm.add_constant(X)
model = smf.OLS(y,X).fit()
predictions = model.predict(X)
print(model.summary())
这篇关于如何在Python statmodels中创建MLR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!