from pandas import DataFrame
import statsmodels.api as sm
Stock_Market = {'股票代码': ['002323', '000520', '000001', '603619'],
'日期':['2020-01-13', '2020-01-13', '2020-01-13', '2020-01-13'],
'市盈率': [-5.56, 141.19, 11.74, -714.83],
'市销率': [-123.16, 5.54, 2.48, 3.22],
'市净率': [7.46, 10.74, 1.23, 2.66],
'市现率': [0,0,0,0],
'市值':[27.4, 43.6, 3297, 63.6]
}
df = DataFrame(Stock_Market,columns=['股票代码','日期','市盈率','市销率','市净率', '市现率', '市值'])
X = df[['市盈率','市销率','市净率']]
Y = df['市值']
X = sm.add_constant(X) # adding a constant
model = sm.OLS(Y, X).fit()
predictions = model.predict(X)
print_model = model.summary()
print(print_model) #输出模型参数
predictions = model.predict(X)
print(predictions) #输出预测结果