范例:
# -*- coding: utf-8 -*-
import pandas as pd
import statsmodels.formula.api as sm
import statsmodels.regression.linear_model as sm
import statsmodels.api as sm2
TV = [230.1, 44.5, 17.2, 151.5, 180.8]
Radio = [37.8,39.3,45.9,41.3,10.8]
Newspaper = [69.2,45.1,69.3,58.5,58.4]
Sales = [22.1, 10.4, 9.3, 18.5,12.9]
df = pd.DataFrame({'TV': TV,
'Radio': Radio,
'Newspaper': Newspaper,
'Sales': Sales})
Y = df.Sales
X = df[['TV','Radio','Newspaper']]
X = sm2.add_constant(X)
model = sm.OLS(Y, X).fit()
new_x = df.loc[df.Sales.notnull(), ['TV', 'Radio', 'Newspaper']].values
new_x = sm2.add_constant(new_x) # sm2 = statsmodels.api
y_predict = model.predict(new_x)
print(df)
print(y_predict)
<<: CMoney第八届菁英软件工程师战斗营_面试经历简述&第一周心得
>>: GCP Container Registry 发生 image tag 为空白的原因及列出空白 tag image 的方法
今天开始要介绍 Structural patterns。先前的 Creational pattern...
React 简单来说是由三个部分组成的 Components (元件) =>可以看作是组成网站...
介面 介面(interface)是JAVA所提供的另一项重要功能,它的结构和抽象类别非常相似。介面本...
首先我们可以先进它的官网稍微浏览一下它的资讯 Shioaji主要有两种语言开发版本,一种是Pytho...
点击物件是蛮基本的操作,不过还是有很多地方需要注意。 回顾 第一天提到了如果该物件是 div,例如这...