第十四周作业

本文使用Python的数据分析工具pandas和统计模型库statsmodels,对Anscombe四重奏数据集进行了深入分析。通过计算各数据集的均值、方差、相关系数,并建立线性回归模型,揭示了即使统计数据相似,数据分布也可能截然不同的现象。

今天老师讲了 pandas ,要求我们用 pandas 、numpy 等工具完成下面两项作业。

老师上课介绍了 Jupyter ,用它来记录 Python 的历史运行记录非常方便,而且还能一键排版,生成 md ,粘上博客。本文就是用 Jupyter 生成的。

%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")

Anscombe’s quartet

Anscombe’s quartet comprises of four datasets, and is rather famous. Why? You’ll find out in this exercise.

anascombe = pd.read_csv('data/anscombe.csv')
anascombe.head()
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
datasetxy
0I10.08.04
1I8.06.95
2I13.07.58
3I9.08.81
4I11.08.33

Part 1

For each of the four datasets…
- Compute the mean and variance of both x and y
- Compute the correlation coefficient between x and y
- Compute the linear regression line: y=β0+β1x+ϵy=β0+β1x+ϵ (hint: use statsmodels and look at the Statsmodels notebook)

anascombe.groupby(['dataset'])[['x', 'y']].mean()
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
xy
dataset
I9.07.500909
II9.07.500909
III9.07.500000
IV9.07.500909
anascombe.groupby(['dataset'])[['x', 'y']].var()
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
xy
dataset
I11.04.127269
II11.04.127629
III11.04.122620
IV11.04.123249
anascombe['x'].corr(anascombe['y'])
0.81636624276147

We can see that the correlation coefficient between x and y is 0.816366242761470.81636624276147

lin_model = smf.ols('y ~ x', anascombe).fit()
lin_model.summary()
OLS Regression Results
Dep. Variable:y R-squared: 0.666
Model:OLS Adj. R-squared: 0.659
Method:Least Squares F-statistic: 83.92
Date:Tue, 12 Jun 2018 Prob (F-statistic):1.44e-11
Time:17:11:06 Log-Likelihood: -67.358
No. Observations: 44 AIC: 138.7
Df Residuals: 42 BIC: 142.3
Df Model: 1
Covariance Type:nonrobust
coefstd errtP>|t|[0.0250.975]
Intercept 3.0013 0.521 5.765 0.000 1.951 4.052
x 0.4999 0.055 9.161 0.000 0.390 0.610














Omnibus: 1.513 Durbin-Watson: 2.327
Prob(Omnibus): 0.469 Jarque-Bera (JB): 0.896
Skew: 0.339 Prob(JB): 0.639
Kurtosis: 3.167 Cond. No. 29.1


Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

We can see that β0=3.0013,β1=0.4999,ε=0.521β0=3.0013,β1=0.4999,ε=0.521

Part 2

Using Seaborn, visualize all four datasets.

hint: use sns.FacetGrid combined with plt.scatter

g = sns.FacetGrid(anascombe, hue='dataset', size=7.5)
g.map(plt.scatter,'x','y').add_legend()
<seaborn.axisgrid.FacetGrid at 0x7f12fbb63128>

这里写图片描述

内容概要:本文围绕六自由度机械臂的人工神经网络(ANN)设计展开,重点研究了正向与逆向运动学求解、正向动力学控制以及基于拉格朗日-欧拉法推导逆向动力学方程,并通过Matlab代码实现相关算法。文章结合理论推导与仿真实践,利用人工神经网络对复杂的非线性关系进行建模与逼近,提升机械臂运动控制的精度与效率。同时涵盖了路径规划中的RRT算法与B样条优化方法,形成从运动学到动力学再到轨迹优化的完整技术链条。; 适合人群:具备一定机器人学、自动控制理论基础,熟悉Matlab编程,从事智能控制、机器人控制、运动学六自由度机械臂ANN人工神经网络设计:正向逆向运动学求解、正向动力学控制、拉格朗日-欧拉法推导逆向动力学方程(Matlab代码实现)建模等相关方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①掌握机械臂正/逆运动学的数学建模与ANN求解方法;②理解拉格朗日-欧拉法在动力学建模中的应用;③实现基于神经网络的动力学补偿与高精度轨迹跟踪控制;④结合RRT与B样条完成平滑路径规划与优化。; 阅读建议:建议读者结合Matlab代码动手实践,先从运动学建模入手,逐步深入动力学分析与神经网络训练,注重理论推导与仿真实验的结合,以充分理解机械臂控制系统的设计流程与优化策略。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值