python的自带数据集_盘点 | Python自带的那些数据集
01
Seaborn自帶數據集
在學習Pandas透視表的時候,大家應該注意到,我們使用的案例數據"泰坦尼克號"來自于seaborn自帶的在線數據庫,我們可以通過seaborn提供的函數load_dataset("數據集名稱")來獲取線上相應的數據,返回給我們的是一個pandas的DataFrame對象。import seaborn as sns
df = sns.load_dataset('titanic')
df.sample(5)
返回的DataFrame對象非常便于我們更加深入地了解數據,示例代碼:df = sns.load_dataset("tips")
print("\n[數據集基本信息]\n")
print(df.info())
print("\n[數值變量信息]\n")
print(df.describe())
print("\n[離散變量信息]\n")
for name in df.dtypes[(df.dtypes == "category") | (df.dtypes == "object")].index:
print("{} 特征值 : {}".format(name, str(df[name].unique())))
數據集描述信息如下:[數據集基本信息]
RangeIndex: 244 entries, 0 to 243
Data columns (total 7 columns):
total_bill 244 non-null float64
tip 244 non-null float64
sex 244 non-null category
smoker 244 non-null category
day 244 non-null category
time 244 non-null category
size 244 non-null int64
dtypes: category(4), float64(2), int64(1)
[數值變量信息]
total_bill tip size
count 244.000000 244.000000 244.000000
mean 19.785943 2.998279 2.569672
std 8.902412 1.383638 0.951100
min 3.070000 1.000000 1.000000
25% 13.347500 2.000000 2.000000
50% 17.795000 2.900000 2.000000
75% 24.127500 3.562500 3.000000
max 50.810000 10.000000 6.000000
[離散變量信息]
sex 特征值 : [Female, Male]
smoker 特征值 : [No, Yes]
day 特征值 : [Sun, Sat, Thur, Fri]
time 特征值 : [Dinner, Lunch]
seaborn自帶的全量數據集,如下所示:seaborn示例數據集鏈接:https://github.com/mwaskom/seaborn-data
02
Sklearn自帶數據集
1. 小型數據集
數據加載、觀察示例:from sklearn import datasets
import pandas as pd, numpy as np
dataset = datasets.load_iris()
print("數據集包含的信息項:")
print(" ".join(dataset.keys()))
print("\n數據集描述信息:\n")
print(dataset["DESCR"])
data = dataset["data"]
target = dataset["target"]
df = pd.DataFrame(data, columns=dataset["feature_names"])
df["target"] = target
df.sample(10)
df.info()
df.describe()sklearn小型數據集詳細介紹:https://scikit-learn.org/stable/datasets/index.html#toy-datasets
2. 較大型數據集(在線下載)
20個新聞組數據集加載示例:from sklearn.datasets import fetch_20newsgroups
from pprint import pprint
newsgroups_train = fetch_20newsgroups(subset='train')
pprint(list(newsgroups_train.targernames))
print(newsgroups_train.filenames.shape) # (11314,)
print(newsgroups_train.target.shape) # (11314,)
print(newsgroups_train.target[:10]) # [ 7 4 4 1 14 16 13 3 2 4]
print(newsgroups_train['data'][:2]) # 前三篇文章["From: lerxst@wam.umd.edu (where's my thin...sklearn大型數據集詳細介紹:https://scikit-learn.org/stable/datasets/index.html#real-world-datasets sklearn
新聞數據文本分類實戰:https://www.jianshu.com/p/244180c064cf
03
其他數據源
1. UCL機器學習知識庫
UCL機器學習數據庫,包括了多個不同大小和類型的數據集,可用于分類、回歸、聚類和推薦系統任務。鏈接:https://archive.ics.uci.edu/ml/index.php
2. weka數據集鏈接:https://www.cs.waikato.ac.nz/ml/weka/datasets.html
3. KD-nuggets數據集鏈接:https://www.kdnuggets.com/datasets/index.html
4. UCI KDD Archive數據集鏈接:http://kdd.ics.uci.edu/
總結
以上是生活随笔為你收集整理的python的自带数据集_盘点 | Python自带的那些数据集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 魔兽世界怀旧服怎么获得魔尘 魔尘获得流程
- 下一篇: DotA2怎么玩单机-DotA2离线单机