Categories
Python

Python Open-Ended Data analysis. It is basically apply a regression model. Only

Python Open-Ended Data analysis. It is basically apply a regression model.
Only thing strange here is that we do not have the data description, but need to find out the relationship by using python do models on. Please view attached, need to upload the jupyer notebook back. No report needed, but need to do vasulizations in python, write short comments on codes, and its data-science aspect meanings.
Please vview attached, it’s open-ended, quite entry one. I will usue the codes to do a presentation for about 15 mins.

Categories
Python

What are Python functions? Why use them Explain the definition, types and the u

What are Python functions? Why use them
Explain the definition, types and the use of Functions.
Provide at least one example.

Categories
Python

Python homework. Someone familiar with that programming language. – Check that s

Python homework. Someone familiar with that programming language.
– Check that space is a number, and is valid (1-9)
– Check that space has not already been taken
– Fix the turn taking
– Check for all winners
– Check for a tie (and show that)
– Add in a “would you like to play again” loop.
I already did the first one.
Let me send you my code.
board = [‘1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9′]
def printboard():
print(board[0],’|’,board[1], ‘|’,board[2])
print(‘–+—+—‘)
print(board[3],’|’,board[4], ‘|’,board[5])
print(‘–+—+—‘)
print(board[6],’|’,board[7], ‘|’,board[8])
print()
def checkwinner():
# Returns TRUE if there’s a winner, FALSE otherwise
if board[0]==board[1]==board[2]:
print(“We have a winner!”)
return True
else:
return False
# Here is my program
printboard()
turn = ‘X’
while not checkwinner():
space= input(“Where do you want to go: “)
if space.isnumeric():
space = int(space)
if space 9:
print (‘sorry buddy – not valid’)
else:
board[space-1]=turn
printboard()
else:
the game has yo work and respect those 5 things

Categories
Python

Can you visualize how many clusters are there?

Note: The main objective of this assignment is to apply the two clustering algorithms (K-means, DBSCAN) on a given dataset. Obviously, preprocessing steps must be done on the data.
In banks, customer loyalty is important since acquiring a new customer is much costlier than retaining an existing customer. Therefore, usually banks would like to predict customer churns. Customer churn refers to the loss of existing clients or customers. These predictions can help banks identify customers who are more likely to close their account and leave the bank. Given the dataset which shows bank customer’s information, we want to cluster their information and learn from it.
In our assignment we will pretend that we don’t know their types (Targets: Attrited or Existing) and would like to cluster them using K-means and DBSCAN, apply dimension reduction and validate our clustering algorithms.
Your Tasks:
Apply all required pre-processing steps to make the data ready for both clustering algorithms. Apply both clustering algorithms on the dataset using your choice of number of clusters, epsilon and minPts.
For the current clusters generated by k-means and DBSCAN, find the silhouette average for all of them and explain which is best.
Run both clustering algorithms again but this time, find the best number of clusters using elbow method (if applicable) and silhouette average (plot the elbow and sillouette average like we saw in the lab)
Explain why this is the best clustering number
Apply PCA on the original dataset and show the variance ratio for all features (like in we saw in lab) and explain them.
After seeing the variance ratio for all features, explain how many dimensions should we use or not use to explain the data.
Plot the dataset in 3D (using top 3 important features). Can you visualize how many clusters are there? Explain.

Categories
Python

However, for the submission which is due this week, i understand that you may not have everything ready at this time, so your introduction submission can be partial, but it should at least cover the following:

Please submit the the Introduction part of your final project here, you need to provide an explanation of the problem and the motivation for solving it. It is acceptable to update this part in your final project submission.
https://www.scribbr.com/research-paper/research-paper-introduction/Links to an external site.
this is a general guideline to come up with scientific paper introduction section, which is required for your final submission(end of semester).
However, for the submission which is due this week, I understand that you may not have everything ready at this time, so your introduction submission can be partial, but it should at least cover the following:
Introduce your topic
Describe the background
Establish your research problem

Categories
Python

Question 1 you decided to make a new investment and buy a condo. you will be ren

Question 1
You decided to make a new investment and buy a condo. You will be renting it out for 35,000 SAR per month. You want to create a program that take the rent amount as an input. Then, calculate the total income that you will receive in 10 years and print out the total for the user.
Question 2
To gain customer loyalty you decided to offer special discounts for loyal customers. Also, offer special discount for new customers to encourage them to stay in business.
Your discount policy will be as the following:
Customer who have less than 100 loyalty points will receive 10% discount.
Customers who have more than 1000 loyalty point will also receive 10% discount.
Create a program that will ask the user to enter their names and how many points do they have. Based on the
collected information, you will print out a message stating if this customer is eligible for discount or not.
Question 3
The ministry of education is trying to encourage a multicultural environment in the school system. To do so, each school has to report the total number of Saudi and non-Saudi students in their classes.
Your job as a programmer is to design a programme to help each instructor with this task.
The program will ask each student to identify their nationality. For example, a question will ask if the student of Saudi nationality or not. The user will answer “Y” for yes and “N” for no. Then calculate the total number of each entry and display it at the end of the program. Keep in mind that the logic of the program will allow the user to continuously enter a value until X is entered.
Question 4
The following list contains a mix of names of countries and cities. Each name is followed by a letter about whether it is part of the GCC countries or European Union.
mixed = [“Bahrain G”, “Austria E”, “Qatar G”, “Malta E”, “Italy E”, “Oman G”, “Kuwait G”, “Denmark E”, “France E”]
Write a program that creates two lists (one of GCC countries, and one of EU) and uses the lists to produce the output.See the file

Categories
Python

Write a function cumulative_sum that mutates the tree t so that each node’s label becomes the sum of all labels in the subtree rooted at the node. def cumulative_sum(t):

Please send the answers in 7-hours. Just 4 questions and you can find a lot of information from online
nd for this lab you need:
Need submit lab9.py file (all questions code inside) and document pdf or Microsoft word lab9
Use Sublime text editor to write your code and use Python shell to execute below programs. Attach Snipping photos of your source code and executions of the code in Python shell.(each question have each one screenshot with code and test all pass have one of screenshot too. I willsend example picture put in the below.)
Make a copy of the assignment template. Go to File => Make a copy (or download as a Word file.)
Complete definitions and attach Snipping Photos where appropriate
Use the book or do online research to find answers. Write your answers using a different font color. Find your own unique color. Write answers in your own words. DO NOT COPY & PASTE from anywhere.
Submission: When done, go to File -> Download as -> Microsoft Word
Lab 09 – Generators – Linked Lists – Trees
Q1: Scale
Implement the generator function scale(s, k), which yields elements of the given iterable s, scaled by k. As an extra challenge, try writing this function using a yield from statement!
def scale(s, k):
“””Yield elements of the iterable s scaled by a number k.
>>> s = scale([1, 5, 2], 5)
>>> type(s)

>>> list(s)
[5, 25, 10]
>>> m = scale(naturals(), 2)
>>> [next(m) for _ in range(5)]
[2, 4, 6, 8, 10]
“””
“*** YOUR CODE HERE ***”
Q2: Link to List
Write a function link_to_list that takes in a linked list and returns the sequence as a Python list. You may assume that the input list is shallow; none of the elements is another linked list.
Try to find both an iterative and recursive solution for this problem!
def link_to_list(link):
“””Takes a linked list and returns a Python list with the same elements.
>>> link = Link(1, Link(2, Link(3, Link(4))))
>>> link_to_list(link)
[1, 2, 3, 4]
>>> link_to_list(Link.empty)
[]
“””
“*** YOUR CODE HERE ***”
Q3: Cumulative Sum
Write a function cumulative_sum that mutates the Tree t so that each node’s label becomes the sum of all labels in the subtree rooted at the node.
def cumulative_sum(t):
“””Mutates t so that each node’s label becomes the sum of all labels in the corresponding subtree rooted at t.
>>> t = Tree(1, [Tree(3, [Tree(5)]), Tree(7)])
>>> cumulative_sum(t)
>>> t
Tree(16, [Tree(8, [Tree(5)]), Tree(7)])
“””
“*** YOUR CODE HERE ***”
Q4: Is BST
Write a function is_bst, which takes a Tree t and returns True if, and only if t is a valid binary search tree, which means that:
Each node has at most two children (a leaf is automatically a valid binary search tree)
The children are valid binary search trees
For every node, the entries in that node’s left child are less than or equal to the label of the node
For every node, the entries in that node’s right child are greater than the label of the node
Note that, if a node has only one child, that child could be considered either the left or right child. You should take this into consideration.
Hint: It may be helpful to write helper functions bst_min and bst_max that return the minimum and maximum, respectively, of a Tree if it is a valid binary search tree.
def is_bst(t):
“””Returns True if the Tree t has the structure of a valid BST.
>>> t1 = Tree(6, [Tree(2, [Tree(1), Tree(4)]), Tree(7, [Tree(7), Tree(8)])])
>>> is_bst(t1)
True
>>> t2 = Tree(8, [Tree(2, [Tree(9), Tree(1)]), Tree(3, [Tree(6)]), Tree(5)])
>>> is_bst(t2)
False
>>> t3 = Tree(6, [Tree(2, [Tree(4), Tree(1)]), Tree(7, [Tree(7), Tree(8)])])
>>> is_bst(t3)
False
>>> t4 = Tree(1, [Tree(2, [Tree(3, [Tree(4)])])])
>>> is_bst(t4)
True
>>> t5 = Tree(1, [Tree(0, [Tree(-1, [Tree(-2)])])])
>>> is_bst(t5)
True
>>> t6 = Tree(1, [Tree(4, [Tree(2, [Tree(3)])])])
>>> is_bst(t6)
True
>>> t7 = Tree(2, [Tree(1, [Tree(5)]), Tree(4)])
>>> is_bst(t7)
False
“””
“*** YOUR CODE HERE ***”

Categories
Python

List average execution time array average execution time 1

Question #1:
(Flattening arrays with flatten vs. ravel) Create a 2-by-3 array containing the
first six powers of 2 beginning with 20. Flatten the array first with method flatten, then
with ravel. In each case, display the result then display the original array to show that it
was unmodified.
Question #2
(Horizontal and Vertical Stacking) Create the two-dimensional arrays
array1 = np.array([[0, 1], [2, 3]])
array2 = np.array([[4, 5], [6, 7]])
a) Use vertical stacking to create the 4-by-2 array named array3 with array1
stacked on top of array2.
b) Use horizontal stacking to create the 2-by-4 array named array4 with array2
to the right of array1.
c) Use vertical stacking with two copies of array4 to create a 4-by-4 array5.
d) Use horizontal stacking with two copies of array3 to create a 4-by-4 array6.
Question #3
(Shallow vs. Deep Copy) In this lecture, we discussed shallow vs. deep copies of
arrays. Python’s built-in list and dictionary types have copy methods that perform shallow
copies. Using the following dictionary
dictionary = {‘Sophia’: [97, 88]}
demonstrate that a dictionary’s copy method indeed performs a shallow copy. To do so,
call copy to make the shallow copy, modify the list stored in the original dictionary, then
display both dictionaries to see that they have the same contents.
Next, use the copy module’s deepcopy function to create a deep copy of the dictionary.
Modify the list stored in the original dictionary, then display both dictionaries to
prove that each has its own data.
Question #4
(Performance Analysis) In this chapter, we used %timeit to compare the average execution
times of generating a list of 6,000,000 random die rolls vs. generating an array of
6,000,000 random die rolls. Though we saw approximately two orders of magnitude performance
improvement with array, we generated the list and the array using two different random-
number generators and different techniques for building each collection. If you use the
same techniques we showed to generate a one-element list and a one-element array, creating
the list is slightly faster. Repeat the %timeit operations for one-element collections. Then do
it again for 10, 100, 1000, 10,000, 100,000, and 1,000,000 elements and compare the results
on your system
Please fill the below table and discuss which is better.
Number of Values
List average execution time array average execution time
1
10
100
1000
10,000
100,000
1,000,000
Question #5
(Pandas: Series) Perform the following tasks with pandas Series:
a) Create a Series from the list [7, 11, 13, 17].
Number of values List average execution time array average execution time
1 1.56 μs ± 25.2 ns 1.89 μs ± 24.4 ns
10 11.6 μs ± 59.6 ns 1.96 μs ± 27.6 ns
100 109 μs ± 1.61 μs 3 μs ± 147 ns
1000 1.09 ms ± 8.59 μs 12.3 μs ± 419 ns
10,000 11.1 ms ± 210 μs 102 μs ± 669 ns
100,000 111 ms ± 1.77 ms 1.02 ms ± 32.9 μs
1,000,000 1.1 s ± 8.47 ms 10.1 ms ± 250 μs
Exercises 279
b) Create a Series with five elements that are all 100.0.
c) Create a Series with 20 elements that are all random numbers in the range 0 to
100. Use method describe to produce the Series’ basic descriptive statistics.
d) Create a Series called temperatures of the floating-point values 98.6, 98.9,
100.2 and 97.9. Using the index keyword argument, specify the custom indices
‘Julie’, ‘Charlie’, ‘Sam’ and ‘Andrea’.
e) Form a dictionary from the names and values in Part (d), then use it to initialize
a Series.
Question # 6
(Pandas: DataFrames) Perform the following tasks with pandas DataFrames:
a) Create a DataFrame named temperatures from a dictionary of three temperature
readings each for ‘Maxine’, ‘James’ and ‘Amanda’.
b) Recreate the DataFrame temperatures in Part (a) with custom indices using
the index keyword argument and a list containing ‘Morning’, ‘Afternoon’
and ‘Evening’.
c) Select from temperatures the column of temperature readings for ‘Maxine’.
d) Select from temperatures the row of ‘Morning’ temperature readings.
e) Select from temperatures the rows for ‘Morning’ and ‘Evening’ temperature
readings.
f) Select from temperatures the columns of temperature readings for ‘Amanda’
and ‘Maxine’.
g) Select from temperatures the elements for ‘Amanda’ and ‘Maxine’ in the
‘Morning’ and ‘Afternoon’.
h) Use the describe method to produce temperatures’ descriptive statistics.
i) Transpose temperatures.
j) Sort temperatures so that its column names are in alphabetical order.

Categories
Python

List average execution time array average execution time 1

Assignment 7b – Array Oriented Programming
Question #1:
(Flattening arrays with flatten vs. ravel) Create a 2-by-3 array containing the
first six powers of 2 beginning with 20. Flatten the array first with method flatten, then
with ravel. In each case, display the result then display the original array to show that it
was unmodified.
Question #2
(Horizontal and Vertical Stacking) Create the two-dimensional arrays
array1 = np.array([[0, 1], [2, 3]])
array2 = np.array([[4, 5], [6, 7]])
a) Use vertical stacking to create the 4-by-2 array named array3 with array1
stacked on top of array2.
b) Use horizontal stacking to create the 2-by-4 array named array4 with array2
to the right of array1.
c) Use vertical stacking with two copies of array4 to create a 4-by-4 array5.
d) Use horizontal stacking with two copies of array3 to create a 4-by-4 array6.
Question #3
(Shallow vs. Deep Copy) In this lecture, we discussed shallow vs. deep copies of
arrays. Python’s built-in list and dictionary types have copy methods that perform shallow
copies. Using the following dictionary
dictionary = {‘Sophia’: [97, 88]}
demonstrate that a dictionary’s copy method indeed performs a shallow copy. To do so,
call copy to make the shallow copy, modify the list stored in the original dictionary, then
display both dictionaries to see that they have the same contents.
Next, use the copy module’s deepcopy function to create a deep copy of the dictionary.
Modify the list stored in the original dictionary, then display both dictionaries to
prove that each has its own data.
Question #4
(Performance Analysis) In this chapter, we used %timeit to compare the average execution
times of generating a list of 6,000,000 random die rolls vs. generating an array of
6,000,000 random die rolls. Though we saw approximately two orders of magnitude performance
improvement with array, we generated the list and the array using two different random-
number generators and different techniques for building each collection. If you use the
same techniques we showed to generate a one-element list and a one-element array, creating
the list is slightly faster. Repeat the %timeit operations for one-element collections. Then do
it again for 10, 100, 1000, 10,000, 100,000, and 1,000,000 elements and compare the results
on your system
Please fill the below table and discuss which is better.
Number of Values
List average execution time array average execution time
1
10
100
1000
10,000
100,000
1,000,000
Question #5
(Pandas: Series) Perform the following tasks with pandas Series:
a) Create a Series from the list [7, 11, 13, 17].
Number of values List average execution time array average execution time
1 1.56 μs ± 25.2 ns 1.89 μs ± 24.4 ns
10 11.6 μs ± 59.6 ns 1.96 μs ± 27.6 ns
100 109 μs ± 1.61 μs 3 μs ± 147 ns
1000 1.09 ms ± 8.59 μs 12.3 μs ± 419 ns
10,000 11.1 ms ± 210 μs 102 μs ± 669 ns
100,000 111 ms ± 1.77 ms 1.02 ms ± 32.9 μs
1,000,000 1.1 s ± 8.47 ms 10.1 ms ± 250 μs
Exercises 279
b) Create a Series with five elements that are all 100.0.
c) Create a Series with 20 elements that are all random numbers in the range 0 to
100. Use method describe to produce the Series’ basic descriptive statistics.
d) Create a Series called temperatures of the floating-point values 98.6, 98.9,
100.2 and 97.9. Using the index keyword argument, specify the custom indices
‘Julie’, ‘Charlie’, ‘Sam’ and ‘Andrea’.
e) Form a dictionary from the names and values in Part (d), then use it to initialize
a Series.
Question # 6
(Pandas: DataFrames) Perform the following tasks with pandas DataFrames:
a) Create a DataFrame named temperatures from a dictionary of three temperature
readings each for ‘Maxine’, ‘James’ and ‘Amanda’.
b) Recreate the DataFrame temperatures in Part (a) with custom indices using
the index keyword argument and a list containing ‘Morning’, ‘Afternoon’
and ‘Evening’.
c) Select from temperatures the column of temperature readings for ‘Maxine’.
d) Select from temperatures the row of ‘Morning’ temperature readings.
e) Select from temperatures the rows for ‘Morning’ and ‘Evening’ temperature
readings.
f) Select from temperatures the columns of temperature readings for ‘Amanda’
and ‘Maxine’.
g) Select from temperatures the elements for ‘Amanda’ and ‘Maxine’ in the
‘Morning’ and ‘Afternoon’.
h) Use the describe method to produce temperatures’ descriptive statistics.
i) Transpose temperatures.
j) Sort temperatures so that its column names are in alphabetical order.

Categories
Python

Do you want a snowman?

Select a landscape scene that you would like to draw using turtle graphics. This can be a simple forest scene, mountain scene, even an outer space scene – it’s up to you!
Import the turtle graphics module and set up your turtle canvas using the turtle.setup() function (see the lecture slides and our course website for some sample code to get you started). Fill the background with a solid color other than white (hint: draw a filled box on your canvas before you draw anything else)
Create at least 5 different shapes (other than the background color from step #3) for your scene. For example, if you wanted to create a forest scene, you could create clouds, trees, a stream, the sun and some mountains for the background. Each shape MUST be written using a function that accepts at least one or more argument(s). You cannot simply call turtle commands from your main program for your shapes – every object should be rendered using its own function. I have chosen to create a Christmas themed landscape. The 6 shapes will be a Christmas tree, snowman(3 circles), star on top of the tree, gifts under the tree, and a string of lights going across the scene, and clouds I want the snow to fall down. Ask the user a question for each shape:Do you want a Christmas Tree? – add circle ornaments to this tree Do you want a snowman? (add buttons and a nose, and some arms)
Do you want to add a star to the tree?
Do you want gifts under the tree? If yes –> how many gifts under the tree (make it < 7) Do you want Christmas lights? Do you want clouds?