Learn with Python training machine

Source: Internet
Author: User

Sample data number, color, foundine, knock, texture, navel, tactile, density, sugar content, good melon  1, green, curled, turbid, clear, sunken, hard slippery, 0.697, 0.46, is  2, black, curled, dull, clear, sunken, hard slippery, 0.774, 0.376, Is  3, black, curled, turbid, clear, sunken, hard slippery, 0.634, 0.264, is  4, green, curled, dull, clear, sunken, hard slippery, 0.608, 0.318, is  5, plain, curled, turbid, clear, sunken, hard slippery, 0.556,0.215, is  6, green, slightly curled, turbid, clear, slightly concave, soft sticky, 0.403, 0.237, is  7, black, slightly curled, turbid, slightly paste, slightly concave, soft sticky, 0.481, 0.149, is  8, black, slightly curled, turbid, clear, slightly concave , hard slip, 0.437, 0.211, is  9, black, slightly curled, dull, slightly mushy, slightly concave, hard slippery, 0.666, 0.091, no  10, green, stiff, crisp, clear, flat, soft sticky, 0.243, 0.267, no  11, plain, stiff, Crisp, blurry, flat, hard slip, 0.245, 0.057, no  12, plain, curled, turbid, blurry, flat, soft sticky, 0.343, 0.099, no  13, turquoise, slightly curled, turbid, slightly mushy, sunken, hard slippery, 0.639, 0.161, no  14, plain, slightly curled, dull, slightly mushy, sunken, hard slippery, 0.657, 0.198, no  15, black, slightly curled, turbid, clear, slightly concave, soft sticky, 0.36, 0.37, no  16, plain, curled, turbid, blurred, flat, hard-slippery, 0.593,0.042, no  17, turquoise, curled, dull, slightly mushy, slightly concave, hard slippery, 0.719, 0.103, no  

  

#前期整理 #-*-Coding:utf-8-*-from itertools import islicedef Test (): values = {' color ': {' Turquoise ': 1,         ' Black ': 2, ' Plain ': 3}, ' root ': {' curled up ': 1, ' slightly curled ': 2, ' Stiff ': 3            }, ' sound ': {' turbid ': 1, ' dull ': 2, ' crisp ': 3}, ' strip ': {             ' Clear ': 1, ' slightly mushy ': 2, ' Blur ': 3}, ' texture ': {' sunken ': 1, ' slightly concave ': 2,            ' Flat ': 3}, ' feel ': {' Hard slip ': 1, ' soft sticky ': 2}, U ' label ': { ' Yes ': 1, ' no ':-1}} fileread = File (' d://a/xigua.txt ', ' R ',-1) Biaotou = Fileread.readline (). strip (' \ n '). Strip (""). Split (",") Biaotouc = Biaotou[1:7] + [Biaotou[-1].strip (' \ n '). Strip ("")] Biaotouen = [' Co        Lor ', ' root ', ' sound ', ' strip ', ' texture ', ' feel ', ' label '] biaotoudict = {} for index in range (len (Biaotouen)): Biaotoudict[biaotouc[index]]        = Biaotouen[index] res = [] for eachline in Fileread.readlines (): Eachlinearray = Eachline.split (', ') Reselem = [] for Elemindex in range (len (eachlinearray)): Eachlinearrayelemindexop=eachlinearray[eleminde X].strip (' \ n '). Strip ("") if (Biaotoudict.has_key (Biaotou[elemindex])): Reselem.append (Values[bi AOTOUDICT[BIAOTOU[ELEMINDEX]]][EACHLINEARRAYELEMINDEXOP]) else:reselem.append (float (eachlinearr AYELEMINDEXOP)) res.append (reselem) print resif __name__ = = ' __main__ ': Test ()

  

Learn with Python training machine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.