Professional Documents
Culture Documents
Sessiya 2-Python
Sessiya 2-Python
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
2
Dərs 2 :
Xülasə
Əhatə ediləcək mövzular
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Probability Distribution 3
Probability can be used for more than calculating the likelihood of one event; it
can summarize the likelihood of all possible outcomes
The structure and type of the probability distribution varies based on the
properties of the random variable, such as continuous or discrete, and this, in
turn, impacts how the distribution might be summarized or how to calculate the
most likely outcome and its probability.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Random Variable 4
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Discrete Random Variable 5
Example: Time
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Discrete Random Variable 7
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Probability Distribution 9
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Skewness 10
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Kurtosis 11
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Discrete random variable distribution 12
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Discrete random variable distribution 13
Probability
2 3 4 5 6 7 8 9 10 11 12
Sum
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Continuous Probability Distributions 14
Temperature 33.3%
3
30.6
22.22% 22.22%
31.4 2
11.1% 11.1%
31.2 1
32.1 30 – 31
31 – 32
32 – 33
33 – 34
34 – 35
32.2
32 – 33
33 – 34
34 – 35
30 – 31
31 – 32
32.7
33.4 Frequency Distribution with Bins Probability of the Bins Probability Density
33.8
34.6
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Normal Distribution 16
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Normal Distribution 17
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Example of Normal Distribution 18
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Positively Skewed Distribution 19
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 20
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 21
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 22
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 23
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 24
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 25
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 26
With the Z value computed, you look up the normal probability using a
table of values from the cumulative standardized normal distribution.
Suppose you wanted to find the probability that the download time for first
example is less than 9 seconds. Recall that transforming to standardized
Z units, given a mean 7 seconds and a standard deviation seconds, leads
to a Z value of +1.00.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 27
With this value, you use Table to find the cumulative area under the
normal curve less than (to the left of) Z = +1.0 To read the probability or
area under the curve less than Z=+1.0 . You scan down the Z column in
Table until you locate the Z value of interest(in 10ths) in the Z row for 1.0.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 28
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Computing Normal Probabilities 29
However, for the other website, you see that a time of 5 seconds is
1 standardized unit above the mean time of 4 seconds. Thus, the
probability that the download time will be less than 5 seconds is also
0.8413.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Challenge 30
What is the probability that the video download time for the
first website will be more than 9 seconds?
What is the probability that the video download time for the
first website will be under 7 seconds or over 9 seconds?
What is the probability that video download time for the first
website will be between 5 and 9 seconds?
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Golden rule 31
For any normal distribution, 68.26% of the values will fall within +-
1 standard deviation of the mean.
95.44% of the values will fall within +-2 standard deviations of the
mean. Thus, 95.44% of the download times are between 3 and
11 seconds.
99.73% of the values are within +-3 standard deviations above or
below the mean. Thus, 99.73% of the download times are between
1 and 13 seconds.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Example 32
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
33
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Rule 34
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Example 35
How much time (in seconds) will elapse before the fastest 10% of
the downloads of an first example video are complete?
Because 10% of the videos are expected to download in under X
seconds, the area under the normal curve less than this value is
0.1000. Using the body of Table, you search for the area or probability
of 0.1000. The closest result is 0.1003, as shown in Table
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Example 36
Working from this area to the margins of the table, you find that the Z
value corresponding to the particular Z row (-1.2) and Z column (.08)
is
-1.28
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Example 37
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Çay fasiləsi
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Finding outliers 39
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Outliers 40
Outliers aren’t always that obvious. Let’s say you received the
following paychecks last month:
$225, $250, $25, $235.
Your average paycheck is $135. But that small paycheck ($25) might be
because you went on vacation, so a weekly paycheck average of $135 isn’t
a true reflection of how much you earned. Your average is actually closer to
$237 if you take the outlier ($25) out of the set.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Outliers 41
Of course, trying to find outliers isn’t always that simple. Your data set
may look like this:
61, 10, 32, 19, 22, 29, 36, 14, 49, 3.
You could take a guess that 3 might be an outlier and perhaps 61. But
you’d be wrong: 61 is the only outlier in this data set.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Boxplot 42
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Finding outliers 43
The most effective way to find all of your outliers is by using the interquartile
range (IQR). The IQR contains the middle bulk of your data, so outliers can
be easily found once you know the IQR.
An outlier is defined as being any point of data that lies over 1.5 IQRs below
the first quartile (Q1) or above the third quartile (Q3)in a data set.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Finding outliers 44
Sample Question: Find the outliers for the following data set: 3, 10, 14, 22, 19,
29, 70, 49, 36, 32.
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Finding outliers 46
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Finding outliers 47
Step 4: Subtract the amount you found in Step 2 from Q1 from Step
1:
14 – 33 = -19.
This is your lower limit. Set this number aside for a moment.
Step 5 : Insert your low and high values into your data set, in order:
-19, 3, 10, 14, 19, 22, 29, 32, 36, 49, 69, 70
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Numpy 49
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Numpy: Arrays 50
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Numpy: Arrays 51
The key difference between an array and a list is, arrays are designed to
handle vectorized operations while a python list is not.
That means, if you apply a function it is performed on every item in the array,
rather than on the whole array object.
A numpy array must have all items to be of the same data type, unlike lists.
This is another significant difference.
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas 52
This tool is essentially your data’s home. Through pandas, you get acquainted with your data by
cleaning, transforming, and analyzing it.
For example, say you want to explore a dataset stored in a CSV on your computer. Pandas will
extract the data from that CSV into a DataFrame — a table, basically — then let you do things like:
• Calculate statistics and answer questions about the data, like
• What's the average, median, max, or min of each column?
• Does column A correlate with column B?
• What does the distribution of data in column C look like?
• Clean the data by doing things like removing missing values and filtering rows or columns by
some criteria
• Visualize the data with help from Matplotlib. Plot bars, lines, histograms, bubbles, and more.
• Store the cleaned, transformed data back into a CSV, other file or database
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas 53
It takes data (like a CSV or TSV file, or a SQL database) and creates a
Python object with rows and columns called data frame that looks very similar
to table in a statistical software (think Excel or SPSS for example.)Pandas is
built on top of the NumPy package, meaning a lot of the structure of NumPy
is used or replicated in Pandas. Data in pandas is often used to feed
statistical analysis in SciPy, plotting functions from Matplotlib, and machine
learning algorithms in Scikit-learn.
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas 54
When you want to use Pandas for data analysis, you’ll usually use it in one of
three different ways:
Convert a Python’s list, dictionary or Numpy array to a Pandas data frame
Open a local file using Pandas, usually a CSV file, but could also be a
delimited text file (like TSV), Excel, etc
Open a remote file or database like a CSV or a JSONon a website through a
URL or read from a SQL table/database
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas 55
There are different filetypes Pandas can work with, so you would replace
“filetype” with the actual, well, filetype (like CSV). You would give the path,
filename etc inside the parenthesis. Inside the parenthesis you can also pass
different arguments that relate to how to open the file. There are numerous
arguments and in order to know all you them, you would have to read the
documentation (for example, the documentation for pd.read_csv() would
contain all the arguments you can pass in this Pandas command).
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas 56
In order to convert a certain Python object (dictionary, lists etc) the basic
command is:
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas: Data viewing 57
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas: Statistics 58
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas: Data selection 59
Selection of Data
• You can select a column (df[col]) and return column with label col
as Series or a few columns (df[[col1, col2]]) and returns columns
as a new DataFrame. You can select by position (s.iloc[0]), or by
index (s.loc['index_one']). In order to select the first row you can
use df.iloc[0,:] and in order to select the first element of the first
column you would run df.iloc[0,0] .
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas 60
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas: Data cleaning 62
After you get a list of missing values you can get rid of them, or drop
them by using df.dropna() to drop the rows or df.dropna(axis=1) to
drop the columns.
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas: Data cleaning 63
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Pandas: join and combine 64
The last set of basic Pandas commands are for joining or combining
data frames or rows/columns. The three commands are:
• df1.append(df2)— add the rows in df1 to the end of df2 (columns
should be identical)
• df.concat([df1, df2],axis=1) — add the columns in df1 to the end of
df2 (rows should be identical)
• df1.join(df2,on=col1,how='inner') — SQL-style join the columns in
df1 with the columns on df2 where the rows for colhave identical
values. how can be equal to one of: 'left', 'right', 'outer', 'inner'
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Çay
fasiləsi
www.qss.a z
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Matplotlib 66
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Scatter plot 67
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Clustering 68
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Density Plot 69
www.qss.az
QSSAnalytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Github 70
www.github.com
Largest web based git repository hosting service
Allows code collaboration
Allows open source projects and documentation
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Git 71
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Git 72
Install git
• https://git-scm.com/downloads
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Git 73
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Git 74
git
config
git git
pull init
git git
push clone
Git
git git
remote add
git git
status commit
git
diff
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Git 75
• git config
Usage: git config –global user.name “[name]”
Usage: git config –global user.email “[email address]”
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Git 76
• git init
This command is used to start a new repository.
• git clone
This command is used to obtain a repository from an existing URL.
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
Git 77
• git remote
Usage: git remote add [variable name] [Remote Server Link]
This command is used to connect your local repository to the remote server.
• git push
Usage: git push [variable name] master
This command sends the committed changes of master branch to your
remote repository.
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.
78
www.qss.az
QSS Analytics/Tədqiqat və İnkişaf Mərkəzi. Bütün hüquqlar qorunur.