dython:Python数据建模宝藏库
尽管已经有了scikit-learn
、statsmodels
、seaborn
等非常优秀的数据建模库,但实际数据分析过程中常用到的一些功能场景仍然需要编写数十行以上的代码才能实现。
而今天要给大家推荐的dython
就是一款集成了诸多实用功能的数据建模工具库,帮助我们更加高效地完成数据分析过程中的诸多任务:
通过下面两种方式均可完成对dython
的安装:
pip install dython
或:
conda install -c conda-forge dython
dython
中目前根据功能分类划分为以下几个子模块:
「data_utils」
data_utils
子模块集成了一些基础性的数据探索性分析相关的API,如identify_columns_with_na()
可用于快速检查数据集中的缺失值情况:
>> df = pd.DataFrame({'col1': ['a', np.nan, 'a', 'a'], 'col2': [3, np.nan, 2, np.nan], 'col3': [1., 2., 3., 4.]})
>> identify_columns_with_na(df)column na_count
1 col2 2
0 col1 1
identify_columns_by_type()
可快速选择数据集中具有指定数据类型的字段:
>> df = pd.DataFrame({'col1': ['a', 'b', 'c', 'a'], 'col2': [3, 4, 2, 1], 'col3': [1., 2., 3., 4.]})
>> identify_columns_by_type(df, include=['int64', 'float64'])
['col2', 'col3']
one_hot_encode()
可快速对数组进行「独热编码」:
>> one_hot_encode([1,0,5])
[[0. 1. 0. 0. 0. 0.][1. 0. 0. 0. 0. 0.][0. 0. 0. 0. 0. 1.]]
split_hist()
则可以快速绘制分组直方图,帮助用户快速探索数据集特征分布:
import pandas as pd
from sklearn import datasets
from dython.data_utils import split_hist# Load data and convert to DataFrame
data = datasets.load_breast_cancer()
df = pd.DataFrame(data=data.data, columns=data.feature_names)
df['malignant'] = [not bool(x) for x in data.target]# Plot histogram
split_hist(df, 'mean radius', split_by='malignant', bins=20, figsize=(15,7))
「nominal」
nominal
子模块包含了一些进阶的特征相关性度量功能,例如其中的associations()
可以自适应由连续型和类别型特征混合的数据集,并自动计算出相应的Pearson
、Cramer's V
、Theil's U
、条件熵等多样化的系数;cluster_correlations()
可以绘制出基于层次聚类的相关系数矩阵图等实用功能:
「model_utils」
model_utils
子模块包含了诸多对机器学习模型进行性能评估的工具,如ks_abc()
:
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from dython.model_utils import ks_abc# Load and split data
data = datasets.load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=.5, random_state=0)# Train model and predict
model = LogisticRegression(solver='liblinear')
model.fit(X_train, y_train)
y_pred = model.predict_proba(X_test)# Perform KS test and compute area between curves
ks_abc(y_test, y_pred[:,1])
metric_graph()
:
import numpy as np
from sklearn import svm, datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import label_binarize
from sklearn.multiclass import OneVsRestClassifier
from dython.model_utils import metric_graph# Load data
iris = datasets.load_iris()
X = iris.data
y = label_binarize(iris.target, classes=[0, 1, 2])# Add noisy features
random_state = np.random.RandomState(4)
n_samples, n_features = X.shape
X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]# Train a model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5, random_state=0)
classifier = OneVsRestClassifier(svm.SVC(kernel='linear', probability=True, random_state=0))# Predict
y_score = classifier.fit(X_train, y_train).predict_proba(X_test)# Plot ROC graphs
metric_graph(y_test, y_score, 'pr', class_names=iris.target_names)
import numpy as np
from sklearn import svm, datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import label_binarize
from sklearn.multiclass import OneVsRestClassifier
from dython.model_utils import metric_graph# Load data
iris = datasets.load_iris()
X = iris.data
y = label_binarize(iris.target, classes=[0, 1, 2])# Add noisy features
random_state = np.random.RandomState(4)
n_samples, n_features = X.shape
X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]# Train a model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5, random_state=0)
classifier = OneVsRestClassifier(svm.SVC(kernel='linear', probability=True, random_state=0))# Predict
y_score = classifier.fit(X_train, y_train).predict_proba(X_test)# Plot ROC graphs
metric_graph(y_test, y_score, 'roc', class_names=iris.target_names)
「sampling」
sampling
子模块则包含了boltzmann_sampling()
和weighted_sampling()
两种数据采样方法,简化数据建模流程。
dython
作为一个处于快速开发迭代过程的Python
库,陆续会有更多的实用功能引入,感兴趣的朋友们可以前往https://github.com/shakedzy/dython
查看更多内容或对此项目保持关注。
以上就是本文的全部内容,欢迎在评论区与我进行讨论~
推荐阅读
Pandas处理数据太慢,来试试Polars吧!
懒人必备!只需一行代码,就能导入所有的Python库
绝!关于pip的15个使用小技巧
介绍10个常用的Python内置函数,99.99%的人都在用!
可能是全网最完整的 Python 操作 Excel库总结!
dython:Python数据建模宝藏库相关推荐
- 二十四、Python数据建模(下),禁止转载
@Author : By Runsen @Date : 2020/5/14 作者介绍:Runsen目前大三下学期,专业化学工程与工艺,大学沉迷日语,Python, Java和一系列数据分析软件.导致翘 ...
- python数据建模数据集_Python中的数据集
python数据建模数据集 There are useful Python packages that allow loading publicly available datasets with j ...
- 数据科学 | Python数据科学常用库
Python 在解决数据科学任务和挑战方面继续处于领先地位. 目录 核心库 IPython NumPy SciPy Pandas StatsModels 可视化 Matplotlib Seaborn ...
- python数据可视化第三方库有哪些_数据可视化!看看程序员大佬都推荐的几大Python库...
数据可视化是数据分析中极为重要的部分,而数据可视化图表(如条形图,散点图,折线图,地理图等)也是非常关键的一环.Python作为数据分析中最流行的编程语言之一,有几个库可以创建精美而复杂的数据可视化, ...
- python数据建模工具_数据探索很麻烦?推荐一款史上最强大的特征分析可视化工具:yellowbrick...
作者:xiaoyu 微信公众号:Python数据科学 前言 玩过建模的朋友都知道,在建立模型之前有很长的一段特征工程工作要做,而在特征工程的过程中,探索性数据分析又是必不可少的一部分,因为如果我们要对 ...
- python可以用来数学建模吗_怎么用Python数学建模:python数据建模工具
怎么用Python数学建模 djcjfhfhhjdvjfhvfghhfgbdthhgdchfjfuivvh DSI方法在几何建模上的应用 本节叙述如何应用DSI方法来与曲面S相联系的二维图形图3.1) ...
- python数据建模工具_python数据分析工具——Pandas、StatsModels、Scikit-Learn
Pandas Pandas是 Python下最强大的数据分析和探索工具.它包含高级的数据结构和精巧的工具,使得在 Python中处理数据非常快速和简单. Pandas构建在 Numpy之上,它使得以 ...
- 二十三、Python数据建模(上),禁止转载
@Author : By Runsen @Date : 2020/5/14 作者介绍:Runsen目前大三下学期,专业化学工程与工艺,大学沉迷日语,Python, Java和一系列数据分析软件.导致翘 ...
- python保存模型 drop_(长期更新)【python数据建模实战】零零散散问题及解决方案梳理...
注1:本文旨在梳理汇总出我们在建模过程中遇到的零碎小问题及解决方案(即当作一份答疑文档),会不定期更新,不断完善, 也欢迎大家提问,我会填写进来. 注2:感谢阅读.为方便您查找想要问题的答案,可以就本 ...
最新文章
- 手把手教你实现PySpark机器学习项目——回归算法
- Comet oj比赛组队
- Swift实现CoreData存储数据
- CSS如何实现内凹角效果 By 大漠
- Beej网络编程指南《三》
- mysql索引类型 normal, unique, full text
- 如何用php饼型图,php绘制饼状图的代码举例
- redis 缓存 淘汰
- linux 重定向命令
- MFC Windows程序设计源码免费下载
- 【精品软件】AE这套神级扩展终于支持2021了,AE脚本-Motion Factory 完整五套解锁版
- 笔者分享:关于Win7 XPS查看器的详细介绍【386w】
- 神舟笔记本进入BIOS的方法
- telnet linux 退格键无法生效
- ppt计算机实验报告册,PPT实验报告册
- 丢花娟(约瑟夫环问题)
- npm install没有node_文件,并且package.json文件缺失
- 目标检测入门(一)两阶段目标检测的由来
- 股东转让股权后是否还应承担出资义务
- springMVC配置多数据源
热门文章
- 反思转变:多努力以积累 多动脑以应变
- node爬取某app数据_某APP次日留存数据报告
- go mysql slave_【Golang+mysql】记一次mysql数据库迁移(一)
- vue组件一直注册不了_【报Bug】现在究竟支不支持Vue.use内注册组件
- zynqpl端时钟_第十二章 ZYNQ-MIZ702 PS读写PL端BRAM
- vant 下拉框样式_使用 Vue 的 Vant.js List 列表组件实现无限下拉
- python打卡记录去重_python中对list去重的多种方法
- 【vue】安装新版本vue-cli:@vue/cli
- 【ruoyi若依】echarts图表跑版
- MySQL复制数据库