[Course] Advanced Computer Programming, Homework, week 14, Jupyter Notebook

这是一篇关于高级计算机编程课程的作业总结,重点介绍了第14周的内容,主要使用了Jupyter Notebook作为工具进行编程和分析。文章分为Part 1和Part 2两个部分,详细探讨了相关编程概念和实践应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# Jupyter Notebook Exercises
%matplotlib inline

import random

import numpy as np
import scipy as sp
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

import statsmodels.api as sm
import statsmodels.formula.api as smf

sns.set_context("talk")
C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\compat\pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead. from pandas.core import datetools
anascombe = pd.read_csv('anscombe.csv')
anascombe.head()
.dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; }
datasetxy
0I10.08.04
1I8.06.95
2I13.07.58
3I9.08.81
4I11.08.33

Part 1

anascombe.groupby(['dataset']).mean()
.dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; }
xy
dataset
I9.07.500909
II9.07.500909
III9.07.500000
IV9.07.500909
anascombe.groupby(['dataset']).std()
.dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; }
xy
dataset
I3.3166252.031568
II3.3166252.031657
III3.3166252.030424
IV3.3166252.030579
anascombe.groupby(['dataset']).corr()
.dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; }
xy
dataset
Ix1.0000000.816421
y0.8164211.000000
IIx1.0000000.816237
y0.8162371.000000
IIIx1.0000000.816287
y0.8162871.000000
IVx1.0000000.816521
y0.8165211.000000
for i in range(4):
    model = smf.ols('y ~ x', anascombe[11*i:11*i+11]).fit()
    print('----'+ str(i) +'----')
    print(model.params)
----0----
Intercept    3.000091
x            0.500091
dtype: float64
----1----
Intercept    3.000909
x            0.500000
dtype: float64
----2----
Intercept    3.002455
x            0.499727
dtype: float64
----3----
Intercept    3.001727
x            0.499909
dtype: float64

Part 2

fig = sns.FacetGrid(anascombe, row='dataset')
fig.map(plt.scatter, 'x', 'y')
<seaborn.axisgrid.FacetGrid at 0x1f1ba7b3d30>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值