sklearn使用LIAC-ARFF加载arff数据

LIAC-ARFF v2.1 Document

import arff

dataset=arff.load(open("D:/res/weather.numeric.arff"))

In [12]: dataset
Out[12]:
{'attributes': [('outlook', ['sunny', 'overcast', 'rainy'
  ('temperature', 'NUMERIC'),
  ('humidity', 'NUMERIC'),
  ('windy', ['TRUE', 'FALSE']),
  ('play', ['yes', 'no'])],
 'data': [['sunny', 85.0, 85.0, 'FALSE', 'no'],
  ['sunny', 80.0, 90.0, 'TRUE', 'no'],
  ['overcast', 83.0, 86.0, 'FALSE', 'yes'],
  ['rainy', 70.0, 96.0, 'FALSE', 'yes'],
  ['rainy', 68.0, 80.0, 'FALSE', 'yes'],
  ['rainy', 65.0, 70.0, 'TRUE', 'no'],
  ['overcast', 64.0, 65.0, 'TRUE', 'yes'],
  ['sunny', 72.0, 95.0, 'FALSE', 'no'],
  ['sunny', 69.0, 70.0, 'FALSE', 'yes'],
  ['rainy', 75.0, 80.0, 'FALSE', 'yes'],
  ['sunny', 75.0, 70.0, 'TRUE', 'yes'],
  ['overcast', 72.0, 90.0, 'TRUE', 'yes'],
  ['overcast', 81.0, 75.0, 'FALSE', 'yes'],
  ['rainy', 71.0, 91.0, 'TRUE', 'no']],
 'description': '',
 'relation': 'weather'}

使用encode_nominal参数后会对标称属性编号,不会存储标称属性真实的属性值

import arff

dataset=arff.load(open("D:/res/weather.numeric.arff"),encode_nominal=True)

In [14]: dataset
Out[14]:
{'attributes': [('outlook', ['sunny', 'overcast', 'rainy']),
  ('temperature', 'NUMERIC'),
  ('humidity', 'NUMERIC'),
  ('windy', ['TRUE', 'FALSE']),
  ('play', ['yes', 'no'])],
 'data': [[0, 85.0, 85.0, 1, 1],
  [0, 80.0, 90.0, 0, 1],
  [1, 83.0, 86.0, 1, 0],
  [2, 70.0, 96.0, 1, 0],
  [2, 68.0, 80.0, 1, 0],
  [2, 65.0, 70.0, 0, 1],
  [1, 64.0, 65.0, 0, 0],
  [0, 72.0, 95.0, 1, 1],
  [0, 69.0, 70.0, 1, 0],
  [2, 75.0, 80.0, 1, 0],
  [0, 75.0, 70.0, 0, 0],
  [1, 72.0, 90.0, 0, 0],
  [1, 81.0, 75.0, 1, 0],
  [2, 71.0, 91.0, 0, 1]],
 'description': '',
 'relation': 'weather'}
In [26]: type(dataset['data'])
Out[26]: list

In [27]: data=np.array(dataset['data'])

你可能感兴趣的:(机器学习)