推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
KIDJourney
V2EX  ›  Python

怎么向 sklearn 导入数据呢?

  •  
  •   KIDJourney ·
    KIDJourney · Jan 10, 2016 · 5155 views
    This topic created in 3956 days ago, the information mentioned may be changed or developed.

    tutorial 里面用的都是内置的数据,我不是太明白怎么把自己的数据给他。

    我的数据集是这样的

    39,State-gov,Bachelors,Never-married,Adm-clerical,Not-in-family,White,Male,2174,0,40,United-States,0
    50,Self-emp-not-inc,Bachelors,Married-civ-spouse,Exec-managerial,Husband,White,Male,0,0,13,United-States,0

    对应

    • 年龄
    • 工作类型
    • 教育程度
    • 婚姻状态
    • 职业
    • 家庭角色
    • 种族
    • 性别
    • 资本收益
    • 资本损失
    • 每周工作时长
    • 原国籍
    • 隶属群组

    请问我该怎样用 sklearn 来导入这组数据呢?

    12 replies  •  2016-01-13 23:07:27 +08:00
    billgreen1
    billgreen1
    Jan 10, 2016
    1
    推荐用 pandas , 可以读取 csv ,数据库,...,各种数据源。

    读取后,是一个 dataframe , 有一个.values 属性,返回的是一个数组。
    KIDJourney
    KIDJourney
    OP
    Jan 10, 2016
    2
    @billgreen1 多谢,我去看看文档。
    话说数据集里面像”婚姻情况“这种特征是不是应该建一个字典然后把 index 放到训练集里面?
    这个 pandas 会自动做吗
    staticor
    staticor
    Jan 10, 2016❤️2
    3
    提供一段代码供参考, 如果分组型字符变量的话要用 0, 1, ... 来离散表示:



    https://gist.github.com/staticor/ee9730d8ef0b01222428
    sleeperqp
    sleeperqp
    Jan 10, 2016❤️1
    4
    @KIDJourney 可以的 你去看下 pandas 例子就知道
    KIDJourney
    KIDJourney
    OP
    Jan 10, 2016
    5
    @sleeperqp
    @staticor

    十分感谢
    sleeperqp
    sleeperqp
    Jan 10, 2016
    6
    用 pandas 读完 csv 然后放入 numpy 就可以了~ 具体的你可以看看例子
    yech1990
    yech1990
    Jan 10, 2016❤️1
    7
    @billgreen1 sklearn 本身就是依赖 pandas 的

    @KIDJourney tutorial 写得很清楚, 建议再仔细看看. 还有就是你想 train 什么模型, 得先搞清楚
    KIDJourney
    KIDJourney
    OP
    Jan 11, 2016
    8
    @yech1990 好的。多谢
    billgreen1
    billgreen1
    Jan 11, 2016
    9
    @yech1990 sklearn 不依赖 pandas ,是依赖 scipy 的。
    Michael728
    Michael728
    Jan 13, 2016
    10
    @sleeperqp 发现这里真是什么大牛都有呀。最近在学 python ,但是数据分析入门感觉挺慢。/(ㄒoㄒ)/~~
    sleeperqp
    sleeperqp
    Jan 13, 2016
    11
    @Michael728 我也是新手弱弱 0 0 多写就好了 最好找点东西做 比如去 kaggle 上找个比赛做做 这样做得快 我觉得主要还是对数据的跟算法的两个理解结合起来才能做好这件事
    KIDJourney
    KIDJourney
    OP
    Jan 13, 2016
    12
    @Michael728 我现在也只是套模型而已,建议先用这些东些做出点东西,有了成就感,再去深入了解底层的知识,这样比较好。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3215 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 10:15 · PVG 18:15 · LAX 02:15 · JFK 05:15
    ♥ Do have faith in what you're doing.