栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python 探索性数据分析方法与应用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python 探索性数据分析方法与应用

探索性数据分析方法与应用 一、频率和众数是简单描述数据分布状况的常见度量 请编写函数实现序列元素频率序列及其众数的计算 并自行构建数据验证方法。

代码

# -*- coding: utf-8 -*-
#频率 and 众数
freDict {}
#统计元素数量
def count(l):
 for item in l:
 if item in freDict.keys():
 freDict[item] 1
 else:
 freDict[item] 1
 return
#求元素频率
def transform():
 s float(sum(freDict.values()))
 for k in freDict.keys():
 freDict[k] / s
 return
#获取众数
def mode():
 max_value list(freDict.values())[0]
 max_key list(freDict.keys())[0]
 for key,value in freDict.items():
 if value max_value:
 max_value value
 max_key key
 return max_key
l [ a , b , c , d , e , a , b , c , d , e , c , d , e ]
count(l)
print( Count for Distinct: ,freDict)
transform()
print( Frequency by precent: ,freDict)
print( Mode: ,mode())

输出结果

二、百分位数也是简单描述数据分布特征的常用度量 请编写函数实现数据序列百分位数的计算 并计算iris数据集中四个属性的百分位数。

代码

# -*- coding: utf-8 -*-
from math import *
import numpy as np
iris np.loadtxt(r E:iris_proc.data ,delimiter , )
rel np.linspace(0,0, 11*5).reshape(11,5)
rel[...,0] range(0,101,10)
for col in range(1,5):
 rel[...,col] [np.percentile(iris[...,col-1], p) for p in rel[...,0]]
print(rel)

输出结果

三、衡量数据序列集中程度的统计量通常由均值、中位数和截断均值 请编写函数分别实现均值、中位数和截断均值的计算 并分别针对iris数据集的四个属性进行计算。

代码

# -*- coding: utf-8 -*-
import math
import numpy as np
def mean(x):
 return sum(x)/ float(len(x))
def median(y):
 x np.sort(y)
 if len(x)%2 0:
 return (x[len(x)//2] x[len(x)//2 1])/2.0
 else:
 return x[len(x)//2]
def trimmean(x,p):
 b np.percentile(x, p//2)
 t np.percentile(x, 100-p//2)
 return mean([i for i in x if b i t])
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/266733.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号