怎么向 sklearn 导入数据呢? - V2EX
推荐学习书目
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

怎么向 sklearn 导入数据呢?

  •  
  •   KIDJourney
    KIDJourney Jan 10, 2016 4745 views
    This topic created in 3799 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
        1
    billgreen1  
       Jan 10, 2016
    推荐用 pandas , 可以读取 csv ,数据库,...,各种数据源。

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



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

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

    @KIDJourney tutorial 写得很清楚, 建议再仔细看看. 还有就是你想 train 什么模型, 得先搞清楚
    KIDJourney
        8
    KIDJourney  
    OP
       Jan 11, 2016
    @yech1990 好的。多谢
    billgreen1
        9
    billgreen1  
       Jan 11, 2016
    @yech1990 sklearn 不依赖 pandas ,是依赖 scipy 的。
    Michael728
        10
    Michael728  
       Jan 13, 2016
    @sleeperqp 发现这里真是什么大牛都有呀。最近在学 python ,但是数据分析入门感觉挺慢。/(ㄒoㄒ)/~~
    sleeperqp
        11
    sleeperqp  
       Jan 13, 2016
    @Michael728 我也是新手弱弱 0 0 多写就好了 最好找点东西做 比如去 kaggle 上找个比赛做做 这样做得快 我觉得主要还是对数据的跟算法的两个理解结合起来才能做好这件事
    KIDJourney
        12
    KIDJourney  
    OP
       Jan 13, 2016
    @Michael728 我现在也只是套模型而已,建议先用这些东些做出点东西,有了成就感,再去深入了解底层的知识,这样比较好。
    About     Help     Advertise     Blog     API     FAQ     Solana     3225 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 38ms UTC 00:18 PVG 08:18 LAX 17:18 JFK 20:18
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86