#
source:
orange/orange/Orange/statistics/basic.py
@
9349:fa13a2c52fcd

Revision 9349:fa13a2c52fcd, 3.6 KB checked in by mitar, 2 years ago (diff) |
---|

Line | |
---|---|

1 | """ |

2 | ========================================== |

3 | Basic Statistics for Continuous Features |

4 | ========================================== |

5 | |

6 | The are two simple classes for computing basic statistics |

7 | for continuous features, such as their minimal and maximal value |

8 | or average: :class:`Orange.statistics.basic.Variable` holds the statistics for a single variable |

9 | and :class:`Orange.statistics.basic.Domain` behaves like a list of instances of |

10 | the above class for all variables in the domain. |

11 | |

12 | .. class:: Variable |

13 | |

14 | Computes and stores minimal, maximal, average and |

15 | standard deviation of a variable. It does not include the median or any |

16 | other statistics that can be computed on the fly, without remembering the |

17 | data; such statistics can be obtained classes from module :obj:`Orange.statistics.distribution`. |

18 | |

19 | Instances of this class are seldom constructed manually; they are more often |

20 | returned by :obj:`Domain` described below. |

21 | |

22 | .. attribute:: variable |

23 | |

24 | The variable to which the data applies. |

25 | |

26 | .. attribute:: min |

27 | |

28 | Minimal value encountered |

29 | |

30 | .. attribute:: max |

31 | |

32 | Maximal value encountered |

33 | |

34 | .. attribute:: avg |

35 | |

36 | Average value |

37 | |

38 | .. attribute:: dev |

39 | |

40 | Standard deviation |

41 | |

42 | .. attribute:: n |

43 | |

44 | Number of instances for which the value was defined. |

45 | If instances were weighted, :obj:`n` holds the sum of weights |

46 | |

47 | .. attribute:: sum |

48 | |

49 | Weighted sum of values |

50 | |

51 | .. attribute:: sum2 |

52 | |

53 | Weighted sum of squared values |

54 | |

55 | .. |

56 | .. attribute:: holdRecomputation |

57 | |

58 | Holds recomputation of the average and standard deviation. |

59 | |

60 | .. method:: add(value[, weight=1]) |

61 | |

62 | Add a value to the statistics: adjust :obj:`min` and :obj:`max` if |

63 | necessary, increase :obj:`n` and recompute :obj:`sum`, :obj:`sum2`, |

64 | :obj:`avg` and :obj:`dev`. |

65 | |

66 | :param value: Value to be added to the statistics |

67 | :type value: float |

68 | :param weight: Weight assigned to the value |

69 | :type weight: float |

70 | |

71 | .. |

72 | .. method:: recompute() |

73 | |

74 | Recompute the average and deviation. |

75 | |

76 | .. class:: Domain |

77 | |

78 | ``statistics.basic.Domain`` behaves like an ordinary list, except that its |

79 | elements can also be indexed by variable names or descriptors. |

80 | |

81 | .. method:: __init__(data[, weight=None]) |

82 | |

83 | Compute the statistics for all continuous variables in the data, and put |

84 | :obj:`None` to the places corresponding to variables of other types. |

85 | |

86 | :param data: A table of instances |

87 | :type data: Orange.data.Table |

88 | :param weight: The id of the meta-attribute with weights |

89 | :type weight: `int` or none |

90 | |

91 | .. method:: purge() |

92 | |

93 | Remove the :obj:`None`'s corresponding to non-continuous features; this |

94 | truncates the list, so the indices do not respond to indices of |

95 | variables in the domain. |

96 | |

97 | part of :download:`distributions-basic-stat.py <code/distributions-basic-stat.py>` (uses :download:`monks-1.tab <code/monks-1.tab>`) |

98 | |

99 | .. literalinclude:: code/distributions-basic-stat.py |

100 | :lines: 1-10 |

101 | |

102 | Output:: |

103 | |

104 | feature min max avg |

105 | sepal length 4.300 7.900 5.843 |

106 | sepal width 2.000 4.400 3.054 |

107 | petal length 1.000 6.900 3.759 |

108 | petal width 0.100 2.500 1.199 |

109 | |

110 | |

111 | part of :download:`distributions-basic-stat.py <code/distributions-basic-stat.py>` (uses :download:`iris.tab <code/iris.tab>`) |

112 | |

113 | .. literalinclude:: code/distributions-basic-stat.py |

114 | :lines: 11- |

115 | |

116 | Output:: |

117 | |

118 | 5.84333467484 |

119 | |

120 | """ |

121 | |

122 | from Orange.core import BasicAttrStat as Variable |

123 | from Orange.core import DomainBasicAttrStat as Domain |

**Note:**See TracBrowser for help on using the repository browser.