given following information:
http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
i need have output that:
- sepal length 2. sepal width 3. petal length 4. petal width 5. class: a. iris setosa b. iris versicolour c. iris virginica
the code needs have output file named iris-summary.txt.
the output file should give average values of sepal , petal lengths , widths. suggested output format is: average sepal length, average sepal width, average petal length, average petal width, class in case correct output formatted as: 6.588, 2.974, 5.552, 2.026, iris-virginica 5.006, 3.418, 1.464, 0.244, iris-setosa 5.936, 2.77, 4.26, 1.326, iris-versicolor
i know need use dictionaries , list comprehension. know need use f.split(",") capability add keys dictionaries can add average them.
if can me code, thanks.
this fiddling did know very far off. pretty created lists , dictionaries , know keys have appended still. need use both dictionary , list?
from __future__ import division, print_function f = ('iris.txt', 'r') f2 = ('iris-summary.txt', 'w') line in f c = f.split(',') l_sl = [] l_sw = [] l_pl = [] l_pw = [] l_c = [] d_sepal_length = {} d_sepal_width = {} d_pedal_length = {} d_pedal_width = {} d_class = {}
k = [s.split(',') s in open('iris.txt').readlines()] sl = sum(s[0] s in k)/len(k)
etc.
Comments
Post a Comment