Reading-Notes

View the Project on GitHub

Dunder Methods

Special Methods and the Python Data Model

Object Initialization: init

used as a constructor to create objects from the class.

Object Representation: str, repr

repr: The “official” string representation of an object. This is how you would make an object of the class. The goal of repr is to be unambiguous.

str: The “informal” or nicely printable string representation of an object. This is for the enduser.

Iteration: len, getitem, reversed

Example of using them:

class className:
     ...

    def __len__(self):
        return len(self._transactions)

    def __getitem__(self, position):
        return self._transactions[position]
        

Operator Overloading for Comparing Accounts: eq, lt

from functools import total_ordering

@total_ordering
class Account:
    # ... (see above)

    def __eq__(self, other):
        return self.balance == other.balance

    def __lt__(self, other):
        return self.balance < other.balance

Operator Overloading for Merging Accounts: add

Callable Python Objects: call

You can make an object callable like a regular function by adding the call dunder method.

Context Manager Support and the With Statement: enter, exit

More ______________________________

Basic Statistics in Python — Probability

Probability: the chance of an event to happen. normal distribution: The normal distribution refers to a particularly important phenomenon in the probability and statistics field.

The most important qualities to notice about the normal distribution is its symmetry and its shape.

difference between the context of probabilities and statistics context in the normal distribution:

Revisiting the normal

The normal distribution is significant to probability and statistics thanks to two factors: the Central Limit Theorem and the Three Sigma Rule.

Central Limit Theorem

Central Limit Theorem lets us know that the average of many trials means will approach the true mean. “ With more trials, the closer the average of these trials approach the true probability, even if the individual trials themselves are imperfect”

Three Sigma Rule

AKA: 68-95-99.7 rule, it is an expression of how many of our observations fall within a certain distance of the mean. given a normal distribution:

Z-score

“Given a data point, how many standard deviations is it away from the mean?”

Statistics module provides functions for calculating mathematical statistics of numeric Real-valued data:

mean(): Arithmetic mean (“average”) of data.

fmean(): Fast, floating point arithmetic mean.

geometric_mean(): Geometric mean of data.

harmonic_mean(): Harmonic mean of data.

median(): Median (middle value) of data.

median_low(): Low median of data.

median_high(): High median of data.

median_grouped(); Median, or 50th percentile, of grouped data.

mode(): Single mode (most common value) of discrete or nominal data.

multimode(): List of modes (most common values) of discrete or nominal data.

quantiles(): Divide data into intervals with equal probability.

pstdev(): Population standard deviation of data.

pvariance(): Population variance of data.

stdev(): Sample standard deviation of data.

variance(): Sample variance of data.

covariance(): Sample covariance for two variables.

correlation(): Pearson’s correlation coefficient for two variables.

linear_regression(): Slope and intercept for simple linear regression.

More ______________________________

Statistical features –>

like bias, variance.. help us explore a dataset to gain valuable insights.

Probability distribution –>

defines the perfect chance that some event will occur, used to understand the spread of data.

Basian statistics –>

expresses probability as a degree of belief in an event which can change as new information is gathered rather than a fixed value based on frequency.

Statistics cheat sheet

Intro to statistics