|
1- |
Py-Multi-pages
Python program, the Machine Learning Crash Course |
|
|
| |
|
|
-
Py-Multi-pages Python program, the Machine
Learning Crash Course
-
Main Form of Crash Course
-
Day 1: Statistics and Machine Learning
-
Day 2: Introduction to Statistics
-
Day 3: Gaussian Distribution & Stats
-
Day 4: Correlation Between Variables
-
Day 5, Statistical Hypothesis Tests
-
Day 6: Estimation Statistics
-
Day 7: Nonparametric Statistics
|
| |
- Create a new Python project In Visual Studio
2022
- the
Microsoft Visual Studio (... or 2019 or 2022) is
a powerful IDE for Python language
- Open/Run
Microsoft Visual Studio 2022
- To view
Python templates, search for python.
 |
Select the
Python
Application template, and select
Next. |
- Create a new Python project In
Visual Studio 2022
On the Configure your new project screen
- (specify a name and file location
for the project, and then select Create)
Project name:
Py-Multi-pages
Location:
C:\Users\...\source\repos
(default location for Visual
Studio 2022)
|
- The new project opens in Visual Studio
2022 - (Visual Studio 2022
Compiler - IDE, to compile Python project /
file )
- The
Visual Studio Solution Explorer window shows the
project structure
- Python
Project Properieties - Py-Multi-pages
- Projct
Folder: C:\Users\...\source\repos\Py-Multi-pages
- Startup
File: Py_Multi_pages.py
- Project
file: Py-Multi-pages.sln
|
- Download Python
Project : Py-Multi-pages.zip -
(9.5 KB zip file) Download
- Project
consist of:
Main Python Form -
(Py_Multi_pages.py )
1 - Python Form -
(Py-Page1.py )
2 - Python Form -
(Py-Page2.py )
3 - Python Form -
(Py-Page3.py )
4 - Python Form -
(Py-Page4.py )
5 - Python Form -
(Py-Page5.py )
6 - Python Form -
(Py-Page6.py )
7 - Python Form -
(Py-Page7.py )
|
 | |
|
Download Python
Project : Py-Multi-pages.zip -
(174 KB zip file) Download
|
|
|
- Install tkinter and PIL in Python on Windows
Operating System, Using Command Prompt
1- Install tkinter in Python on Windows Operating System,
Using Command Prompt
pip install tkinter |
|
|
| 2- Install PIL in Python on Windows Operating System,
Using Command Prompt |
|
pip install PIL |
|
|
| |
Source Code of Python Project -Py-Multi-pages :
|
Main |
|
| |
|
Download this Source Code at
python file: Py_Multi_pages.py - (2.5 KB Python file)
download |
 |
Continue
|
Py_Multi_pages.py Python Code, Main Form
of Crash course | |
|
|
| |
# This Python file uses the following encoding:
utf-8 # Python With Multi Pages/Days
import
tkinter
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
import
os
root = Tk()
root.title( "Home
Page, the Machine Learning Crash Course")
root.geometry( "750x600+300+40")
root.resizable( False,
False)
global
root_window
is_admin =
False
root_window = root
def
on_existing():
root.destroy()
def
on_closing():
global
is_on
window.destroy()
def
draw_info_page():
global
window
newWindow =
Toplevel(root_window)
newWindow.title( "General
info")
newWindow.geometry( "370x230+500+200")
newWindow.configure( bg= "#fbb1bd")
newWindow.resizable(0, 0)
# This will create a LabelFrame
label_frame =
LabelFrame(newWindow,
text='')
label_frame.pack(expand= 'yes',
fill='both')
label11 =
Label(label_frame,
text='
Name: Chucri Simon zouein.')
label11.place(x=0, y=5)
label21 =
Label(label_frame,
text='
Address: Lebanon, Beirut, Sed ElBaouchrie,
Ferdaous Str.')
label21.place(x=0, y=35)
label31 =
Label(label_frame,
text='
Signification: Engineer on Software System
science.')
label31.place(x=0, y=65)
label41 =
Label(label_frame,
text='
Web: www.puresoftwarecode.com.')
label41.place(x=0, y=95)
label51 =
Label(label_frame,
text='
Tel: 961 01 591436.')
label51.place(x=0, y=125)
#5- line
lertline= Label(newWindow,
text="",font=("Times
New Roman",8,),
bg =
"#118ab2",fg="#eae2b7")
lertline.place(x=0, y=165, width=400)
#6- emailButton
emaill =
Label(newWindow,
text ="echkzouein@gmail.com",
font=("Times
New Roman",
12), relief = FLAT)
emaill.place(x=50, y=190)
submit=
Button(newWindow,
text="Done",
command = on_closing, font=("Times
New Roman",
14), bd =2, bg =
"#118ab2",fg="#eae2b7",
relief=RAISED)
submit.place(x=250, y=190, width = 100,
height = 30)
newWindow.protocol( "WM_DELETE_WINDOW",
on_closing)
window = newWindow
def
draw_page1():
os.system( 'python
py-Page1.py')
def
draw_page2():
# import py-Page2.py
os.system( 'python
py-Page2.py')
def
draw_page3():
# import py-Page3.py
os.system( 'python
py-Page3.py')
def
draw_page4():
# import py-Page4.py
os.system( 'python
py-Page4.py')
def
draw_page5():
# import py-Page5.py
os.system( 'python
py-Page5.py')
def
draw_page6():
# import py-Page6.py
os.system( 'python
py-Page6.py')
def
draw_page7():
# import py-Page7.py
os.system( 'python
py-Page7.py')
def
draw_visitor():
for
widget
in
dashboard.winfo_children():
widget.destroy()
image1 =
Image.open("media/MachineLearningCourse.jpg")
test = ImageTk. PhotoImage(image1)
label1 =
Label(dashboard,image=test)
label1.photo = test
label1.place(x=0, y=0, height = 400, width =
400)
option=
Button(dashboard,
text ="Day
1: Statistics and Machine Learning",
command = draw_page1, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=0, width = 300, height
= 30)
option=
Button(dashboard,
text ="Day
2: Introduction to Statistics",
command = draw_page2, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=60, width = 300, height
= 30)
option=
Button(dashboard,
text ="Day
3: Gaussian Distribution & Stats",
command = draw_page3, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=120, width = 300,
height = 30)
option=
Button(dashboard,
text ="Day
4: Correlation Between Variables",
command = draw_page4, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=180, width = 300,
height = 30)
option=
Button(dashboard,
text ="Day
5, Statistical Hypothesis Tests",
command =draw_page5, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=240, width = 300,
height = 30)
option=
Button(dashboard,
text ="Day
6: Estimation Statistics",
command = draw_page6, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=300, width = 300,
height = 30)
option=
Button(dashboard,
text ="Day
7: Nonparametric Statistics",
command =draw_page7, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=360, width = 300,
height = 30)
option=
Button(dashboard,
text ="General
Info",
command = draw_info_page,bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=410, y=420, width = 300,
height = 30)
option=
Button(dashboard,
text ="Exit",
command = on_existing, bd =0, font=("Times
New Roman",14),
bg =
"#118ab2",fg="#eae2b7")
option.place(x=100, y=420, width = 200,
height = 30)
#Header
header= Frame(root,
bg =
"#118ab2",
bd=0)
header.place(x=0,y=0,width=1080,height=75)
#logo
image1 =
Image.open("media/logo1.jpg")
test = ImageTk. PhotoImage(image1)
label1 = tkinter. Label(header,image=test)
label1.image = test
label1.place(x=20, y=5, height = 65)
#heading label
nsec= Label(header,
text="the
Machine Learning Crash Course.",font=("Times
New Roman",20,"bold"
), bg =
"#118ab2",fg="#eae2b7")
nsec.place(x=190, y=35, width=550)
is_on =
True
dashboard= Frame(root,
bd=0)
dashboard.place(x=0,y=100,width=1080,height=450)
draw_visitor()
#Footer
footer= Frame(root,
bg =
"#118ab2",
bd=0)
footer.place(x=0,y=565,width=1080,height=85)
root.mainloop()
|
|
| | |
|
| |
|
| |
|
|
Day 1 |
- Statistics and Machine Learning |
| |
|
Download this Source Code at
python file: py-Page1.py - (5.58 KB Python file)
download
|
 |
Continue
|
py-Page1.py Python Code, Day 1 -
Statistics and Machine Learning | |
|
|
| |
# This Python file uses the following encoding:
utf-8
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
def
on_closing():
root.destroy()
root =
Tk()
root.title( "The
Machine Learning - Day 1: Statistics and Machine
Learning")
root.eval( 'tk::PlaceWindow
. center')
window_height = 700
window_width = 1000
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate =
int((screen_width/2)
- (window_width/2))
y_cordinate =
int((screen_height/2)
- (window_height/2))
root.geometry( "{}x{}+{}+{}".format(window_width,
window_height, x_cordinate, y_cordinate))
root.resizable(0, 0)
#Labels
lbselected1= Label(root,text="Statistics
and Machine Learning, Discover the 5 reasons why
a machine learning practitioner should deepen
their understanding of statistics.",font=("Times
New Roman",
12), foreground="#000080")
lbselected1.place(x=17, y=3)
# Statistics and Machine Learning
Frame0a = tk. Frame(root)
Frame0a.place(relx=0.01, rely=0.05, relheight=0.69,
relwidth=0.47)
Frame0a.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text0a = tk. Text(Frame0a,
borderwidth="0")
# Create text widget and specify size.
Fact =
"""1. Statistics in Data Preparation
Statistical methods are required in the
preparation of train and test data for your
machine learning model.
This includes techniques for:
1.1- Outlier detection.
1.2- Missing value imputation.
1.3- Data sampling.
1.4- Data scaling.
1.5-Variable encoding.
1.6- And much more.
A basic understanding of data distributions,
descriptive statistics, and data visualization
is required to help you identify the methods to
choose when performing these tasks
2. Statistics in Model Evaluation
Statistical methods are required when
evaluating the skill of a machine learning model
on data not seen during training.
This includes techniques for:
2.1- Data sampling.
2.2- Data resampling.
2.2- Experimental design.
Resampling techniques such as k-fold
cross-validation are often well understood by
machine learning practitioners, but the
rationale for why this method is required is
not.
3. Statistics in Model Selection
Statistical methods are required when
selecting a final model or model configuration
to use for a predictive modeling problem.
"""
##to List 3 reasons why you personally want
to learn statistics.
#l.pack()
Text0a.pack(fill=BOTH, expand=1)
# Insert The Fact.
Text0a.insert(tk.END, Fact)
# Continue Statistics and Machine Learning
# Create text widget and specify size.
Frame0b = tk. Frame(root)
Frame0b.place(relx=0.52, rely=0.05, relheight=0.69,
relwidth=0.47)
Frame0b.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text0b = tk. Text(Frame0b,
borderwidth="0")
Fact =
"""These include techniques for:
3.1- Checking for a significant difference
between
results.
3.2- Quantifying the size of the difference
between
results.
This might include the use of statistical
hypothesis tests
4. Statistics in Model Presentation
Statistical methods are required when
presenting the skill of a final model to
stakeholders.
This includes techniques for:
4.1- Summarizing the expected skill of the
model on
average.
4.2- Quantifying the expected variability of
the
skill of the model in practice.
This might include estimation statistics such
as confidence intervals.
5. Statistics in Prediction
Statistical methods are required when making
a prediction with a finalized model on new data.
This includes techniques for:
5.1- Quantifying the expected variability for
the
prediction.
This might include estimation statistics such
as prediction intervals.
"""
Text0b.pack(fill=BOTH, expand=1)
# Insert The Fact.
Text0b.insert(tk.END, Fact)
lblinex= Label(root,text="------------------------------------------",font=("Times
New Roman",
12))
lblinex.place(x=350, y=520)
lbline01= Label(root,text="to
List 3 reasons why you personally want to learn
statistics.",font=("Times
New Roman",
10))
lbline01.place(x=10, y=540)
# to List 3 reasons why you personally want
to learn statistics.
Frame1a = tk. Frame(root)
Frame1a.place(relx=0.01, rely=0.81, relheight=0.15,
relwidth=0.47)
Frame1a.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text11a = tk. Text(Frame1a,
borderwidth="0")
Fact =
"""these 3 Reasons Statistics to learn
statistics
1- Statistics in Data Preparation
2- Statistics in Model Selection
3- Statistics in Model Presentation
"""
Text11a.pack()
print ('Day
1 - 3 Reasons Statistics')
print ('1-
Statistics in Data Preparation')
print ('2-
Statistics in Model Selection')
print ('3-
Statistics in Model Presentation')
print ('')
# Insert The Fact.
Text11a.insert(tk.END, Fact)
Frame1b = tk. Frame(root)
Frame1b.place(relx=0.52, rely=0.81, relheight=0.15,
relwidth=0.37)
Frame1b.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
#2- Image
image1 =
Image.open("media/MachineL.jpg")
test = ImageTk. PhotoImage(image1)
label11= tk. Label(Frame1b,image=test)
label11.image = test
label11.place(x=6, y=6)
#Button
close =
Button(root,
text =
"Done",
command = on_closing)
close.place(x=900, y=600, height = 30, width
= 90)
root.mainloop() |
|
| | |
|
| |
|
| |
|
|
Day 2 |
- Introduction to Statistics |
| |
|
Download this Source Code at
python file: py-Page2.py - (4.90 KB Python file)
download
|
 |
Continue
|
py-Page2.py
Python Code, Day 2 -
Introduction to Statistics | |
|
|
| |
# This Python file uses the following encoding:
utf-8
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
def
on_closing():
root.destroy()
root =
Tk()
root.title( "The
Machine Learning - Day 2: Introduction to
Statistics")
root.eval( 'tk::PlaceWindow
. center')
window_height = 450
window_width = 1000
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate =
int((screen_width/2)
- (window_width/2))
y_cordinate =
int((screen_height/2)
- (window_height/2))
root.geometry( "{}x{}+{}+{}".format(window_width,
window_height, x_cordinate, y_cordinate))
root.resizable(0, 0)
#Labels
lbselected1= Label(root,text="Introduction
to Statistics, Discover a concise definition of
statistics.",font=("Times
New Roman",
12), foreground="#000080")
lbselected1.place(x=15, y=5)
# Statistics and Machine Learning
Frame0a = tk. Frame(root)
Frame0a.place(relx=0.01, rely=0.08, relheight=0.49,
relwidth=0.47)
Frame0a.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text0a = tk. Text(Frame0a,
borderwidth="0")
# Create text widget and specify size.
Fact =
"""Statistics is a required prerequisite for
most books and courses on applied machine
learning. But what exactly is statistics?
Statistics is a subfield of mathematics. It
refers to a collection of methods for working
with data and using data to answer questions.
It is because the field is comprised of a
grab bag of methods for working with data that
it can seem large and amorphous to beginners. It
can be hard to see the line between methods that
belong to statistics and methods that belong to
other fields of study.
"""
##to List 3 reasons why you personally want
to learn statistics.
#l.pack()
Text0a.pack(fill=BOTH, expand=1)
# Insert The Fact.
Text0a.insert(tk.END, Fact)
# Continue Statistics and Machine Learning
# Create text widget and specify size.
Frame0b = tk. Frame(root)
Frame0b.place(relx=0.52, rely=0.08, relheight=0.49,
relwidth=0.47)
Frame0b.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text0b = tk. Text(Frame0b,
borderwidth="0")
Fact =
"""When it comes to the statistical tools that
we use in practice, it can be helpful to divide
the field of statistics into two large groups of
methods: descriptive statistics for summarizing
data, and inferential statistics for drawing
conclusions from samples of data.
1- Descriptive Statistics: Descriptive
statistics refer
to methods for summarizing raw observations
into
information that we can understand and share.
2- Inferential Statistics: Inferential
statistics is
a fancy name for methods that aid in
quantifying
properties of the domain or population from a
smaller set of obtained observations called a
sample
"""
Text0b.pack(fill=BOTH, expand=1)
# Insert The Fact.
Text0b.insert(tk.END, Fact)
lblinex= Label(root,text="------------------------------------------",font=("Times
New Roman",
12))
lblinex.place(x=350, y=265)
lbline01= Label(root,text="to
list three methods that can be used for each
descriptive and inferential statistics..",font=("Times
New Roman",
10))
lbline01.place(x=10, y=295)
# to list three methods that can be used for
each descriptive and inferential statistics..
Frame1a = tk. Frame(root)
Frame1a.place(relx=0.01, rely=0.72, relheight=0.22,
relwidth=0.47)
Frame1a.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text11a = tk. Text(Frame1a,
borderwidth="0")
Fact =
"""
List of 3 methods used for each descriptive
and inferential statistics
1- Descriptive statistics: Measures Of
Central Tendency,
Standard deviation, Scatter plots
2- Inferential statistics: Confidence
intervals,
Regression analysis, ANOVA
"""
Text11a.pack()
Text11a.pack()
print ('Day
2 - List of 3 methods used for each descriptive
and inferential statistics')
print ('1-
Descriptive statistics: Measures Of Central
Tendency, Standard deviation, Scatter plots')
print ('2-
Inferential statistics: Confidence intervals,
Regression analysis, ANOVA')
print ('')
# Insert The Fact.
Text11a.insert(tk.END, Fact)
Frame1b = tk. Frame(root)
Frame1b.place(relx=0.52, rely=0.72, relheight=0.22,
relwidth=0.37)
Frame1b.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
#2- Image
image1 =
Image.open("media/MachineL.jpg")
test = ImageTk. PhotoImage(image1)
label11= tk. Label(Frame1b,image=test)
label11.image = test
label11.place(x=6, y=4)
#Button
close =
Button(root,
text =
"Done",
command = on_closing)
close.place(x=900, y=360, height = 30, width
= 90)
root.mainloop() |
|
| | |
|
| |
|
|
Day 3 |
- Gaussian Distribution & Stats |
| |
|
Download this Source Code at
python file: py-Page3.py - (6.90 KB Python file)
download
|
 |
Continue
|
py-Page3.py
Python Code, Day 3 - Gaussian
Distribution & Stats | |
|
|
| |
# This Python file uses the following encoding:
utf-8
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
def
on_closing():
root.destroy()
root =
Tk()
root.title( "The
Machine Learning - Day 3: Gaussian Distribution
and Descriptive Stats")
root.eval( 'tk::PlaceWindow
. center')
window_height = 630
window_width = 1000
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate =
int((screen_width/2)
- (window_width/2))
y_cordinate =
int((screen_height/2)
- (window_height/2))
root.geometry( "{}x{}+{}+{}".format(window_width,
window_height, x_cordinate, y_cordinate))
root.resizable(0, 0)
#Labels
lbselected1= Label(root,text="Gaussian
Distribution and Descriptive Stats",font=("Times
New Roman",
12,"bold"),
foreground="#000080")
lbselected1.place(x=17, y=5)
lbline1= Label(root,text="you
will discover the Gaussian distribution for data
and how to calculate simple descriptive
statistics",font=("Times
New Roman",
10))
lbline1.place(x=17, y=40)
lbline2= Label(root,text="A
sample of data is a snapshot from a broader
population of all possible observations that
could be taken from a domain or generated by a
process.",font=("Times
New Roman",
10))
lbline2.place(x=17, y=60)
lbline3= Label(root,text="Interestingly,
many observations fit a common pattern or
distribution called the normal distribution, or
more formally, the Gaussian distribution. It is
the bell shaped distribution",font=("Times
New Roman",
10))
lbline3.place(x=17, y=80)
lbline4= Label(root,text="
that you may be familiar with.",font=("Times
New Roman",
10))
lbline4.place(x=17, y=100)
lbline5= Label(root,text="A
lot is known about the Gaussian distribution,
and as such, there are whole sub-fields of
statistics and statistical methods that can be
used with Gaussian data.",font=("Times
New Roman",
10))
lbline5.place(x=17, y=120)
lbline6= Label(root,text="Any
Gaussian distribution, and in turn any data
sample drawn from a Gaussian distribution, can
be summarized with just two parameters:",font=("Times
New Roman",
10))
lbline6.place(x=17, y=140)
lbline7= Label(root,text="
1- Mean. The central tendency or most likely
value in the distribution (the top of the
bell).",font=("Times
New Roman",
10))
lbline7.place(x=17, y=160)
lbline8= Label(root,text="
2- Variance. The average difference that
observations have from the mean value in the
distribution (the spread).",font=("Times
New Roman",
10))
lbline8.place(x=17, y=180)
lbline9= Label(root,text="The
units of the mean are the same as the units of
the distribution, although the units of the
variance are squared, and therefore harder to
interpret. A popular alternative to ",font=("Times
New Roman",
10))
lbline9.place(x=17, y=200)
lbline10= Label(root,text="
the variance parameter is the standard
deviation, which is simply the square root of
the variance, returning the units to be the same
as those of the distribution.",font=("Times
New Roman",
10))
lbline10.place(x=17, y=220)
lbline11= Label(root,text="The
mean, variance, and standard deviation can be
calculated directly on data samples in NumPy",font=("Times
New Roman",
10))
lbline11.place(x=17, y=240)
lblinex= Label(root,text="------------------------------------------",font=("Times
New Roman",
12))
lblinex.place(x=350, y=265)
lbline12= Label(root,text="Example:
to Generate a sample of 100 random numbers drawn
from a Gaussian distribution with a known mean
of 50 and a standard deviation of 5 and
calculates the summary statistics.",font=("Times
New Roman",
10))
lbline12.place(x=17, y=290)
# Display the Code, to Calculate Summary
Stats
Frame1 = tk. Frame(root)
Frame1.place(relx=0.01, rely=0.51, relheight=0.39,
relwidth=0.47)
Frame1.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text11 = tk. Text(Frame1,
borderwidth="0")
# Create text widget and specify size.
# Create label
l =
Label(Frame1,
text =
"the Code, to Calculate Summary Stats")
l.config(font =( "Times
New Roman",
12))
Fact =
"""from numpy.random import seed
from numpy.random import randn
from numpy import mean
from numpy import var
from numpy import std
# seed the random number generator
seed(1)
# generate univariate observations
data = 5 * randn(10000) + 50
# calculate statistics
print('Mean: %.3f' % mean(data))
print('Variance: %.3f' % var(data))
print('Standard Deviation: %.3f' % std(data))"""
##Run the example and compare the estimated
mean and standard deviation from the expected
values
l.pack()
Text11.pack()
# Insert The Fact.
Text11.insert(tk.END, Fact)
Frame2 = tk. Frame(root)
Frame2.place(relx=0.52, rely=0.51, relheight=0.39,
relwidth=0.47)
Frame2.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
#The example below generates a sample of 100
random numbers drawn from a Gaussian
distribution with a known mean of 50 and a
standard deviation of 5 and calculates the
summary statistics.
#Run the example and compare the estimated
mean and standard deviation from the expected
values
# calculate summary stats
from
numpy.random
import
seed
from
numpy.random
import
randn
from
numpy
import
mean
from
numpy
import
var
from
numpy
import
std
# seed the random number generator
seed(1)
# generate univariate observations
data = 5 * randn(10000) + 50
# calculate statistics
print ('Day
3 - calculate statistics ')
print ('Mean:
%.3f'
% mean(data))
print ('Variance:
%.3f'
% var(data))
print ('Standard
Deviation: %.3f'
% std(data))
print ('')
# Create label
l2 =
Label(Frame2,
text =
"the Values of the Summary Stats")
l2.config(font =( "Times
New Roman",
12))
l2.pack()
mymean = tk. StringVar()
myvariance = tk. StringVar()
mystandard = tk. StringVar()
mymean = mean(data)
myvariance = var(data)
mystandard =std(data)
mylabelmean0 =
Label(Frame2,
text ="Mean:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelmean0.place(x=40, y=40)
mylabelmean1 = tk. Label(Frame2,
width=20, text=mymean)
mylabelmean1.place(x=170, y=40)
mylabelvariance0 =
Label(Frame2,
text ="Variance:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelvariance0.place(x=40, y=70)
mylabelvariance1 = tk. Label(Frame2,
width=20, text=myvariance)
mylabelvariance1.place(x=170, y=70)
mylabelstandard0 =
Label(Frame2,
text ="Standard
Deviation:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelstandard0.place(x=40, y=100)
mylabelstandard1 = tk. Label(Frame2,
width=20, text=mystandard)
mylabelstandard1.place(x=170, y=100)
#2- Image
image1 =
Image.open("media/MachineL.jpg")
test = ImageTk. PhotoImage(image1)
label11= tk. Label(Frame2,image=test)
label11.image = test
label11.place(x=60, y=140)
#Button
close =
Button(root,
text =
"Done",
command = on_closing)
close.place(x=700, y=585, height = 30, width
= 120)
root.mainloop() |
|
| | |
|
| |
|
| |
|
|
Day 4 |
- Correlation Between Variables |
| |
|
Download this Source Code at
python file: py-Page4.py - (6.38 KB Python file)
download
|
 |
Continue
|
py-Page4.py
Python Code, Day 4 - Correlation
Between Variables | |
|
|
| |
# This Python file uses the following encoding:
utf-8
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
def
on_closing():
root.destroy()
root =
Tk()
root.title( "The
Machine Learning - Day 4: Correlation Between
Variables")
root.eval( 'tk::PlaceWindow
. center')
window_height = 700
window_width = 1000
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate =
int((screen_width/2)
- (window_width/2))
y_cordinate =
int((screen_height/2)
- (window_height/2))
root.geometry( "{}x{}+{}+{}".format(window_width,
window_height, x_cordinate, y_cordinate))
root.resizable(0, 0)
#Labels
lbselected1= Label(root,text="Correlation
Between Variables",font=("Times
New Roman",
12,"bold"),
foreground="#000080")
lbselected1.place(x=17, y=5)
lbline1= Label(root,text="how
to calculate a correlation coefficient to
quantify the relationship between two
variables.",font=("Times
New Roman",
10))
lbline1.place(x=17, y=40)
lbline2= Label(root,text="Variables
in a dataset may be related for lots of
reasons.",font=("Times
New Roman",
10))
lbline2.place(x=17, y=60)
lbline3= Label(root,text="It
can be useful in data analysis and modeling to
better understand the relationships between
variables. The statistical relationship between
two variables is referred to as",font=("Times
New Roman",
10))
lbline3.place(x=17, y=80)
lbline4= Label(root,text="
their correlation.",font=("Times
New Roman",
10))
lbline4.place(x=17, y=100)
lbline5= Label(root,text="A
correlation could be positive, meaning both
variables move in the same direction, or
negative, meaning that when one variable's value
increases, the other variables -",font=("Times
New Roman",
10))
lbline5.place(x=17, y=120)
lbline6= Label(root,text="
values decrease:",font=("Times
New Roman",
10))
lbline6.place(x=17, y=140)
lbline7= Label(root,text="
1- Positive Correlation: Both variables change
in the same direction.",font=("Times
New Roman",
10))
lbline7.place(x=17, y=160)
lbline8= Label(root,text="
2- Neutral Correlation: No relationship in the
change of the variables.",font=("Times
New Roman",
10))
lbline8.place(x=17, y=180)
lbline9= Label(root,text="
3- Negative Correlation: Variables change in
opposite directions.",font=("Times
New Roman",
10))
lbline9.place(x=17, y=200)
lbline10= Label(root,text="The
performance of some algorithms can deteriorate
if two or more variables are tightly related,
called multicollinearity. An example is linear
regression, where one of the ",font=("Times
New Roman",
10))
lbline10.place(x=17, y=220)
lbline11= Label(root,text="
offending correlated variables should be removed
in order to improve the skill of the model.",font=("Times
New Roman",
10))
lbline11.place(x=17, y=240)
lbline12= Label(root,text="We
can quantify the relationship between samples of
two variables using a statistical method called
Pearson's correlation coefficient, named for the
developer of the method, ",font=("Times
New Roman",
10))
lbline12.place(x=17, y=260)
lbline13= Label(root,text="
Karl Pearson.",font=("Times
New Roman",
10))
lbline13.place(x=17, y=280)
lbline14= Label(root,text="The
pearsonr() NumPy function can be used to
calculate the Pearson's correlation coefficient
for samples of two variables.",font=("Times
New Roman",
10))
lbline14.place(x=17, y=300)
lblinex= Label(root,text="------------------------------------------",font=("Times
New Roman",
12))
lblinex.place(x=350, y=320)
lbline15= Label(root,text="Example
is listed below showing the calculation where
one variable is dependent upon the second.",font=("Times
New Roman",
10))
lbline15.place(x=17, y=340)
# Display the Code, to Calculate Correlation
Coefficient
Frame1 = tk. Frame(root)
Frame1.place(relx=0.01, rely=0.53, relheight=0.37,
relwidth=0.47)
Frame1.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text11 = tk. Text(Frame1,
borderwidth="0")
# Create text widget and specify size.
# Create label
l =
Label(Frame1,
text =
"the Code, to Calculate Correlation Coefficient")
l.config(font =( "Times
New Roman",
12))
Fact =
"""from numpy.random import seed
from numpy.random import randn
from scipy.stats import pearsonr
# seed the random number generator
seed(1)
# prepare data
data1 = 20 * randn(1000) + 100
data2 = data1 + (10 * randn(1000) + 50)
# calculate Pearson's correlation
corr, p = pearsonr(data1, data2)
# display the correlation
print('Pearsons correlation: %.3f' % corr)"""
#Run the example and review the calculated
correlation coefficient
l.pack()
Text11.pack()
# Insert The Fact.
Text11.insert(tk.END, Fact)
Frame2 = tk. Frame(root)
Frame2.place(relx=0.52, rely=0.53, relheight=0.37,
relwidth=0.47)
Frame2.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
#Example is listed below showing the
calculation where one variable is dependent upon
the second.
#Run the example and review the calculated
correlation coefficient
# to Calculate Correlation Coefficient
from
numpy.random
import
seed
from
numpy.random
import
randn
from
scipy.stats
import
pearsonr
Messg1 = tk. StringVar()
Messg2 = tk. StringVar()
# seed the random number generator
seed(1)
##
# prepare data
data1 = 20 * randn(1000) + 100
data2 = data1 + (10 * randn(1000) + 50)
# calculate Pearson's correlation
corr, p = pearsonr(data1, data2)
# display the correlation
print ('Day
4 - display the correlation')
print ('Pearsons
correlation: %.3f'
% corr)
print ('')
# Create label
l2 =
Label(Frame2,
text =
"the Values of the Example of the Mann-whitney U
Test")
l2.config(font =( "Times
New Roman",
12))
l2.pack()
#corr, p = pearsonr(data1, data2)
corr1 = tk. StringVar()
corr1=
'%.3f'
% corr
mylabelcorr0 =
Label(Frame2,
text ="Pearsons
Correlation:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelcorr0.place(x=40, y=40)
mylabelcorr1 = tk. Label(Frame2,
width=20, text=corr1)
mylabelcorr1.place(x=170, y=40)
#2- Image
image1 =
Image.open("media/MachineL.jpg")
test = ImageTk. PhotoImage(image1)
label11= tk. Label(Frame2,image=test)
label11.image = test
label11.place(x=60, y=140)
#Button
close =
Button(root,
text =
"Done",
command = on_closing)
close.place(x=800, y=650, height = 30, width
= 120)
root.mainloop() |
|
| | |
|
| |
|
| |
|
|
Day 5 |
- Statistical Hypothesis Tests |
| |
|
Download this Source Code at
python file: py-Page5.py - (8.02 KB Python file)
download
|
 |
Continue
|
py-Page5.py
Python Code, Day 5 - Statistical
Hypothesis Tests | |
|
|
| |
# This Python file uses the following encoding:
utf-8
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
def
on_closing():
root.destroy()
root =
Tk()
root.title( "The
Machine Learning - Day 5, Statistical Hypothesis
Tests")
root.eval( 'tk::PlaceWindow
. center')
window_height = 700
window_width = 1000
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate =
int((screen_width/2)
- (window_width/2))
y_cordinate =
int((screen_height/2)
- (window_height/2))
root.geometry( "{}x{}+{}+{}".format(window_width,
window_height, x_cordinate, y_cordinate))
root.resizable(0, 0)
#Labels
lbselected1= Label(root,text="Statistical
Hypothesis Tests",font=("Times
New Roman",
12,"bold"),
foreground="#000080")
lbselected1.place(x=17, y=1)
lbline0= Label(root,text="you
will discover statistical hypothesis tests and
how to compare two samples.",font=("Times
New Roman",
10))
lbline0.place(x=17, y=30)
lbline1= Label(root,text="Data
must be interpreted in order to add meaning. We
can interpret data by assuming a specific
structure our outcome and use statistical
methods to confirm or reject the assumption.",font=("Times
New Roman",
10))
lbline1.place(x=17, y=50)
lbline2= Label(root,text="The
assumption is called a hypothesis and the
statistical tests used for this purpose are
called statistical hypothesis tests.",font=("Times
New Roman",
10))
lbline2.place(x=17, y=70)
lbline3= Label(root,text="The
assumption of a statistical test is called the
null hypothesis, or hypothesis zero (H0 for
short). It is often called the default
assumption, or the assumption that nothing has",font=("Times
New Roman",
10))
lbline3.place(x=17, y=90)
lbline4= Label(root,text="
changed. A violation of the test's assumption is
often called the first hypothesis, hypothesis
one, or H1 for short.",font=("Times
New Roman",
10))
lbline4.place(x=17, y=110)
lbline5= Label(root,text="
1- Hypothesis 0 (H0): Assumption of the test
holds and is failed to be rejected.",font=("Times
New Roman",
10))
lbline5.place(x=17, y=130)
lbline6= Label(root,text="
2- Hypothesis 1 (H1): Assumption of the test
does not hold and is rejected at some level of
significance.",font=("Times
New Roman",
10))
lbline6.place(x=17, y=150)
lbline7= Label(root,text="We
can interpret the result of a statistical
hypothesis test using a p-value. The p-value is
the probability of observing the data, given the
null hypothesis is true.",font=("Times
New Roman",
10))
lbline7.place(x=17, y=170)
lbline8= Label(root,text="A
large probability means that the H0 or default
assumption is likely. A small value, such as
below 5% (0.05) suggests that it is not likely
and that we can reject H0 in favor of",font=("Times
New Roman",
10))
lbline8.place(x=17, y=190)
lbline9= Label(root,text="
H1, or that something is likely to be different
(e.g. a significant result).",font=("Times
New Roman",
10))
lbline9.place(x=17, y=210)
lbline10= Label(root,text="A
widely used statistical hypothesis test is the
Student's t-test for comparing the mean values
from two independent samples.",font=("Times
New Roman",
10))
lbline10.place(x=17, y=230)
lbline11= Label(root,text="The
default assumption is that there is no
difference between the samples, whereas a
rejection of this assumption suggests some
significant difference. The test assumes that",font=("Times
New Roman",
10))
lbline11.place(x=17, y=250)
lbline12= Label(root,text="
both samples were drawn from a Gaussian
distribution and have the same variance.",font=("Times
New Roman",
10))
lbline12.place(x=17, y=270)
lbline13= Label(root,text="The
Student's t-test can be implemented in Python
via the ttest_ind() SciPy function.",font=("Times
New Roman",
10))
lbline13.place(x=17, y=290)
lblinex= Label(root,text="------------------------------------------",font=("Times
New Roman",
12))
lblinex.place(x=45, y=310)
lbline14= Label(root,text="Below
is an example of calculating and interpreting
the Student's t-test for two data samples that
are known to be different.",font=("Times
New Roman",
10))
lbline14.place(x=17, y=330)
# Display the Code of Calculating and
interpreting the Student's t-test
# to example of the mann-whitney u test
Frame1 = tk. Frame(root)
Frame1.place(relx=0.01, rely=0.53, relheight=0.43,
relwidth=0.47)
Frame1.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text11 = tk. Text(Frame1,
borderwidth="0")
# Create text widget and specify size.
# Create label
l =
Label(Frame1,
text =
"the Code of Calculating and interpreting the
Student's t-test")
l.config(font =( "Times
New Roman",
12))
Fact =
"""from numpy.random import seed
from numpy.random import rand
from scipy.stats import ttest_ind
# seed the random number generator
seed(1)
# generate two independent samples
data1 = 5 * randn(100) + 50
data2 = 5 * randn(100) + 51
# compare samples
stat, p = ttest_ind(data1, data2)
print('Statistics=%.3f, p=%.3f' % (stat, p))
# interpret
alpha = 0.05
if p > alpha:
print('Same distribution (fail to reject
H0)')
else:
print('Different distribution (reject
H0)')"""
##Run the example and review the calculated
statistics and interpretation of the p-value.
l.pack()
Text11.pack()
# Insert The Fact.
Text11.insert(tk.END, Fact)
Frame2 = tk. Frame(root)
Frame2.place(relx=0.52, rely=0.53, relheight=0.43,
relwidth=0.47)
Frame2.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
#Below is an example of calculating and
interpreting the Student's t-test for two data
samples that are known to be different.
#Run the code and review the calculated
statistic and interpretation of the p-value.
# student's t-test
from
numpy.random
import
seed
from
numpy.random
import
randn
from
scipy.stats
import
ttest_ind
Messg1 = tk. StringVar()
Messg2 = tk. StringVar()
# seed the random number generator
seed(1)
# generate two independent samples
data1 = 5 * randn(100) + 50
data2 = 5 * randn(100) + 51
# compare samples
print ('Day
5 - compare samples')
stat, p = ttest_ind(data1, data2)
print ('Statistics=%.3f,
p=%.3f'
% (stat, p))
# interpret
alpha = 0.05
if
p > alpha:
#print('Same distribution (fail to reject H0)')
Messg1 = "p
> 0,05 - Same distribution (fail to reject H0)"
print(Messg1)
else :
#print('Different distribution (reject H0)')
Messg2= "p
< 0,05 - Different distribution (reject H0)"
print(Messg2)
print ('')
# Create label
l2 =
Label(Frame2,
text =
"the Values of Calculating and interpreting the
Student's t-test")
l2.config(font =( "Times
New Roman",
12))
l2.pack()
stat1 = tk. StringVar()
p1 = tk. StringVar()
Messag1 = tk. StringVar()
Messag2 = tk. StringVar()
#stat, p = ttest_ind(data1, data2)
#print('Statistics=%.3f, p=%.3f' % (stat, p))
stat1=
str(stat)
p1=
str(p)
Messag1 = Messg1
Messag2 = Messg2
mylabelstst0 =
Label(Frame2,
text ="Statistics,
stat:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelstst0.place(x=40, y=40)
mylabelstst1 = tk. Label(Frame2,
width=20, text= stat1)
#str(stat)) #stat1)
mylabelstst1.place(x=170, y=40)
mylabelp0 =
Label(Frame2,
text ="Statistics,
p:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelp0.place(x=40, y=70)
mylabelp1 = tk. Label(Frame2,
width=20, text=p1)
mylabelp1.place(x=170, y=70)
mylabelMessage0 =
Label(Frame2,
text = Messag1, font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelMessage0.place(x=50, y=100)
mylabelMessage1 =
Label(Frame2,
text = Messag2, font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelMessage1.place(x=50, y=100)
#2- Image
image1 =
Image.open("media/MachineL.jpg")
test = ImageTk. PhotoImage(image1)
label11= tk. Label(Frame2,image=test)
label11.image = test
label11.place(x=60, y=140)
#Button
close =
Button(root,
text =
"Done",
command = on_closing)
close.place(x=850, y=320, height = 30, width
= 120)
root.mainloop() |
|
| | |
|
| |
|
| |
|
|
Day 6 |
- Estimation Statistics |
| |
|
Download this Source Code at
python file: py-Page6.py - (8.14 KB Python file)
download
|
 |
Continue
|
py-Page6.py
Python Code, Day 6 - Estimation
Statistics | |
|
|
| |
# This Python file uses the following encoding:
utf-8
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
def
on_closing():
root.destroy()
root =
Tk()
root.title( "The
Machine Learning - Day 6: Estimation Statistics")
root.eval( 'tk::PlaceWindow
. center')
window_height = 700
window_width = 1000
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate =
int((screen_width/2)
- (window_width/2))
y_cordinate =
int((screen_height/2)
- (window_height/2))
root.geometry( "{}x{}+{}+{}".format(window_width,
window_height, x_cordinate, y_cordinate))
root.resizable(0, 0)
#Labels
lbselected1= Label(root,text="Statistical
Hypothesis Tests",font=("Times
New Roman",
12,"bold"),
foreground="#000080")
lbselected1.place(x=17, y=3)
#lbselected2=Label(root,text="
-------------------------------------------------------------",font=("Times
New Roman", 10), foreground="#000080")
#lbselected2.place(x=17, y=24)
lbline1= Label(root,text="you
will discover estimation statistics that may be
used as an alternative to statistical hypothesis
tests.",font=("Times
New Roman",
10))
lbline1.place(x=17, y=20)
lbline2= Label(root,text="Statistical
hypothesis tests can be used to indicate whether
the difference between two samples is due to
random chance, but cannot comment on the size of
the difference.",font=("Times
New Roman",
10))
lbline2.place(x=17, y=40)
lbline3= Label(root,text="A
group of methods referred to as \textit{new
statistics} are seeing increased use instead",font=("Times
New Roman",
10))
lbline3.place(x=17, y=60)
lbline4= Label(root,text="
of or in addition to p-values in order to
quantify the magnitude of effects and the amount
of uncertainty for ",font=("Times
New Roman",
10))
lbline4.place(x=17, y=80)
lbline4a= Label(root,text="
estimated values. This group of statistical
methods is referred to as estimation
statistics.",font=("Times
New Roman",
10))
lbline4a.place(x=17, y=100)
lbline5= Label(root,text="Estimation
statistics is a term to describe three main
classes of methods. The three main classes of
methods include:",font=("Times
New Roman",
10))
lbline5.place(x=17, y=120)
lbline6= Label(root,text="
1- Effect Size. Methods for quantifying the size
of an effect given a treatment or intervention.",font=("Times
New Roman",
10))
lbline6.place(x=17, y=140)
lbline7= Label(root,text="
2- Interval Estimation. Methods for quantifying
the amount of uncertainty in a value.",font=("Times
New Roman",
10))
lbline7.place(x=17, y=160)
lbline8= Label(root,text="
3- Meta-Analysis. Methods for quantifying the
findings across multiple similar studies.",font=("Times
New Roman",
10))
lbline8.place(x=17, y=180)
lbline9= Label(root,text="Of
the three, perhaps the most useful methods in
applied machine learning are interval
estimation.",font=("Times
New Roman",
10))
lbline9.place(x=17, y=200)
lbline10= Label(root,text="There
are three main types of intervals. They are:",font=("Times
New Roman",
10))
lbline10.place(x=17, y=220)
lbline11= Label(root,text="
1- Tolerance Interval: The bounds or coverage of
a proportion of a distribution with a specific
level of confidence.",font=("Times
New Roman",
10))
lbline11.place(x=17, y=240)
lbline12= Label(root,text="
2- Confidence Interval: The bounds on the
estimate of a population parameter.",font=("Times
New Roman",
10))
lbline12.place(x=17, y=260)
lbline13= Label(root,text="
3- Prediction Interval: The bounds on a single
observation.",font=("Times
New Roman",
10))
lbline13.place(x=17, y=280)
lbline14= Label(root,text="A
simple way to calculate a confidence interval
for a classification algorithm is to calculate
the binomial proportion confidence interval,",font=("Times
New Roman",
10))
lbline14.place(x=17, y=300)
lbline15= Label(root,text="
which can provide an interval around a model's
estimated accuracy or error.",font=("Times
New Roman",
10))
lbline15.place(x=17, y=320)
lbline16= Label(root,text="This
can be implemented in Python using the conf_int()
statsmodels function.",font=("Times
New Roman",
10))
lbline16.place(x=17, y=340)
lbline17= Label(root,text="The
function takes the count of successes (or
failures), the total number of trials, and the
significance level as arguments and returns ",font=("Times
New Roman",
10))
lbline17.place(x=17, y=360)
lbline18= Label(root,text="
the lower and upper bound of the confidence
interval.",font=("Times
New Roman",
10))
lbline18.place(x=17, y=380)
lblinex= Label(root,text="------------------------------------------",font=("Times
New Roman",
12))
lblinex.place(x=350, y=400)
lbline19= Label(root,text="The
example below demonstrates this function in a
hypothetical case where a model made 88 correct
predictions out of a dataset ",font=("Times
New Roman",
10))
lbline19.place(x=17, y=420)
lbline20= Label(root,text="
with 100 instances and we are interested in the
95% confidence interval (provided to the
function as a significance of 0.05).",font=("Times
New Roman",
10))
lbline20.place(x=17, y=440)
#The example below demonstrates this function
in a hypothetical case where a model made 88
correct predictions out of a dataset with 100
instances and we are interested in the 95%
confidence interval (provided to the function as
a significance of 0.05).
#Run the example and review the confidence
interval on the estimated accuracy.
# Display the Code, to Calculate the
Confidence Interval
Frame1 = tk. Frame(root)
Frame1.place(relx=0.01, rely=0.67, relheight=0.24,
relwidth=0.48)
Frame1.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text11 = tk. Text(Frame1,
borderwidth="0")
# to Calculate the Confidence Interval
# Create label
l =
Label(Frame1,
text =
"the Code, to Calculate the Confidence Interval")
l.config(font =( "Times
New Roman",
12))
Fact =
"""
from statsmodels.stats.proportion import
proportion_confint
# calculate the interval
lower, upper = proportion_confint(88, 100,
0.05)
print('lower=%.3f, upper=%.3f' % (lower,
upper))"""
#Run the example and review the confidence
interval on the estimated accuracy.
l.pack()
Text11.pack()
# Insert The Fact.
Text11.insert(tk.END, Fact)
Frame2 = tk. Frame(root)
Frame2.place(relx=0.52, rely=0.67, relheight=0.24,
relwidth=0.47)
Frame2.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
#The example below demonstrates this function
in a hypothetical case where a model made 88
correct predictions out of a dataset with 100
instances and we are interested in the 95%
confidence interval (provided to the function as
a significance of 0.05).
#Run the example and review the confidence
interval on the estimated accuracy.
# to Calculate Correlation Coefficient
from
statsmodels.stats.proportion
import
proportion_confint
# calculate the interval
print ('Day
6 - calculate the interval')
lower, upper = proportion_confint(88, 100,
0.05)
print ('lower=%.3f,
upper=%.3f'
% (lower, upper))
print ('')
# Create label
l2 =
Label(Frame2,
text =
"the Values to Calculate the Confidence
Interval")
l2.config(font =( "Times
New Roman",
12))
l2.pack()
lower1 = tk. StringVar()
upper1 = tk. StringVar()
#lower, upper = proportion_confint(88, 100,
0.05)
lower1 = lower
upper1 = upper
mylabellower0 =
Label(Frame2,
text ="Lower
=",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabellower0.place(x=40, y=40)
mylabellower1 = tk. Label(Frame2,
width=20, text=lower1)
mylabellower1.place(x=170, y=40)
mylabelupper0 =
Label(Frame2,
text ="Upper
=",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelupper0.place(x=40, y=40)
mylabelupper1 = tk. Label(Frame2,
width=20, text=upper1)
mylabelupper1.place(x=170, y=40)
#2- Image
image1 =
Image.open("media/MachineL.jpg")
test = ImageTk. PhotoImage(image1)
label11= tk. Label(Frame2,image=test)
label11.image = test
label11.place(x=60, y=70)
#Button
close =
Button(root,
text =
"Done",
command = on_closing)
close.place(x=800, y=650, height = 30, width
= 120)
root.mainloop()
|
|
| | |
|
| |
|
|
Day 7 |
- Nonparametric Statistics |
| |
|
Download this Source Code at
python file: py-Page7.py - (7.60 KB Python file)
download
|
 |
Continue
|
py-Page7.py
Python Code, Day 7 - Nonparametric
Statistics | |
|
|
| |
# This Python file uses the following encoding:
utf-8
import
tkinter
as tk
from
tkinter
import
*
from
PIL
import
Image,
ImageTk
def
on_closing():
root.destroy()
root =
Tk()
root.title( "The
Machine Learning - Day 7: Nonparametric
Statistics")
root.eval( 'tk::PlaceWindow
. center')
window_height = 700
window_width = 1000
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate =
int((screen_width/2)
- (window_width/2))
y_cordinate =
int((screen_height/2)
- (window_height/2))
root.geometry( "{}x{}+{}+{}".format(window_width,
window_height, x_cordinate, y_cordinate))
root.resizable(0, 0)
#Labels
lbselected1= Label(root,text="Nonparametric
Statistics",font=("Times
New Roman",
12,"bold"),
foreground="#000080")
lbselected1.place(x=17, y=5)
lbline1= Label(root,text="you
will discover statistical methods that may be
used when your data does not come from a
Gaussian distribution.",font=("Times
New Roman",
10))
lbline1.place(x=17, y=40)
lbline2= Label(root,text="A
large portion of the field of statistics and
statistical methods is dedicated to data where
the distribution is known.",font=("Times
New Roman",
10))
lbline2.place(x=17, y=60)
lbline3= Label(root,text="Data
in which the distribution is unknown or cannot
be easily identified is called nonparametric.",font=("Times
New Roman",
10))
lbline3.place(x=17, y=80)
lbline4= Label(root,text="In
the case where you are working with
nonparametric data, specialized nonparametric
statistical methods can be used that discard all
information about the distribution. As such, ",font=("Times
New Roman",
10))
lbline4.place(x=17, y=100)
lbline5= Label(root,text="
these methods are often referred to as
distribution-free methods.",font=("Times
New Roman",
10))
lbline5.place(x=17, y=120)
lbline6= Label(root,text="Before
a nonparametric statistical method can be
applied, the data must be converted into a rank
format. As such, statistical methods that expect
data in rank format",font=("Times
New Roman",
10))
lbline6.place(x=17, y=140)
lbline7= Label(root,text="
are sometimes called rank statistics, such as
rank correlation and rank statistical hypothesis
tests. Ranking data is exactly as its name
suggests.",font=("Times
New Roman",
10))
lbline7.place(x=17, y=160)
lbline8= Label(root,text="The
procedure is as follows:",font=("Times
New Roman",
10))
lbline8.place(x=17, y=180)
lbline9= Label(root,text="
1- Sort all data in the sample in ascending
order.",font=("Times
New Roman",
10))
lbline9.place(x=17, y=200)
lbline10= Label(root,text="
2- Assign an integer rank from 1 to N for each
unique value in the data sample.",font=("Times
New Roman",
10))
lbline10.place(x=17, y=220)
lbline11= Label(root,text="A
widely used nonparametric statistical hypothesis
test for checking for a difference between two
independent samples is the Mann-Whitney U test,
named for ",font=("Times
New Roman",
10))
lbline11.place(x=17, y=240)
lbline12= Label(root,text="
Henry Mann and Donald Whitney.",font=("Times
New Roman",
10))
lbline12.place(x=17, y=260)
lbline13= Label(root,text="It
is the nonparametric equivalent of the Student's
t-test but does not assume that the data is
drawn from a Gaussian distribution.",font=("Times
New Roman",
10))
lbline13.place(x=17, y=280)
lbline14= Label(root,text="The
test can be implemented in Python via the
mannwhitneyu() SciPy function.",font=("Times
New Roman",
10))
lbline14.place(x=17, y=300)
lblinex= Label(root,text="------------------------------------------",font=("Times
New Roman",
12))
lblinex.place(x=350, y=320)
lbline15= Label(root,text="The
example below demonstrates the test on two data
samples drawn from a uniform distribution known
to be different.",font=("Times
New Roman",
10))
lbline15.place(x=17, y=340)
# Display the Code of the example of the
mann-whitney u test
Frame1 = tk. Frame(root)
Frame1.place(relx=0.01, rely=0.53, relheight=0.43,
relwidth=0.47)
Frame1.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
Text11 = tk. Text(Frame1,
borderwidth="0")
#the example of the mann-whitney u test
# Create label
l =
Label(Frame1,
text =
"the Code of the example of the mann-whitney u
test")
l.config(font =( "Times
New Roman",
12))
Fact =
"""from numpy.random import seed
from numpy.random import rand
from scipy.stats import mannwhitneyu
# seed the random number generator
seed(1)
# generate two independent samples
data1 = 50 + (rand(100) * 10)
data2 = 51 + (rand(100) * 10)
# compare samples
stat, p = mannwhitneyu(data1, data2)
print('Statistics=%.3f, p=%.3f' % (stat, p))
# interpret
alpha = 0.05
if p > alpha:
print('Same distribution (fail to reject
H0)')
else:
print('Different distribution (reject H0)')
"""
##Run the example and review the calculated
statistics and interpretation of the p-value.
l.pack()
Text11.pack()
# Insert The Fact.
Text11.insert(tk.END, Fact)
Frame2 = tk. Frame(root)
Frame2.place(relx=0.52, rely=0.53, relheight=0.43,
relwidth=0.47)
Frame2.configure(relief= "groove",
borderwidth="0",
background="#ffffff",
highlightbackground="#ffffff",
highlightcolor="black",
width=870)
#The example below demonstrates the test on
two data samples drawn from a uniform
distribution known to be different.
#Run the example and review the calculated
statistics and interpretation of the p-value.
# the example of the mann-whitney u test
from
numpy.random
import
seed
from
numpy.random
import
rand
from
scipy.stats
import
mannwhitneyu
Messg1 = tk. StringVar()
Messg2 = tk. StringVar()
# seed the random number generator
seed(1)
# generate two independent samples
data1 = 50 + (rand(100) * 10)
data2 = 51 + (rand(100) * 10)
# compare samples
print ('Day
7 - compare samples')
stat, p = mannwhitneyu(data1, data2)
print ('Statistics=%.3f,
p=%.3f'
% (stat, p))
# interpret
alpha = 0.05
if
p > alpha:
#print('Same distribution (fail to reject H0)')
Messg1 = "p
> 0,05 - Same distribution (fail to reject H0)"
print(Messg1)
else :
#print('Different distribution (reject H0)')
Messg2= "p
< 0,05 - Different distribution (reject H0)"
print(Messg2)
print ('')
# Create label
l2 =
Label(Frame2,
text =
"the Values of the Example of the mann-whitney u
Test")
l2.config(font =( "Times
New Roman",
12))
l2.pack()
stat1 = tk. StringVar()
p1 = tk. StringVar()
stat1= str(stat)
p1= str(p)
Messag1 = tk. StringVar()
Messag2 = tk. StringVar()
#stat, p = mannwhitneyu(data1, data2)
Messag1 = Messg1
Messag2 = Messg2
mylabelstst0 =
Label(Frame2,
text ="Statistics,
stat:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelstst0.place(x=40, y=40)
mylabelstst1 = tk. Label(Frame2,
width=20, text=stat)
mylabelstst1.place(x=170, y=40)
mylabelp0 =
Label(Frame2,
text ="Statistics,
p:",
font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelp0.place(x=40, y=70)
mylabelp1 = tk. Label(Frame2,
width=20, text=p)
mylabelp1.place(x=170, y=70)
mylabelMessage0 =
Label(Frame2,
text = Messag1, font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelMessage0.place(x=50, y=100)
mylabelMessage1 =
Label(Frame2,
text = Messag2, font=("Times
New Roman",
12), relief = FLAT, background="#ffffff")
mylabelMessage1.place(x=50, y=100)
#2- Image
image1 =
Image.open("media/MachineL.jpg")
test = ImageTk. PhotoImage(image1)
label11= tk. Label(Frame2,image=test)
label11.image = test
label11.place(x=60, y=160)
#Button
close =
Button(root,
text =
"Done",
command = on_closing)
close.place(x=850, y=320, height = 30, width
= 120)
root.mainloop() |
|
| | |
|
| |
|
| |
|
- Debug Py-Multi-pages project, 0 Errors
Output of Python Project, Py-Multi-pages
- Desktop Forms:
|
| | | |
|