IB3M10-python代写
时间:2023-05-15
IB3M10 Page 6 of 7
Question 3
All questions below refer to the programming language Python.
3.1 Suppose you would like to store an inventory of student names together with the corre-
sponding student marks for two modules, call them Module A and Module B. What data
type would you use? Describe how you would arrange it and provide an example.
[2 marks]
3.2 Describe what the following script does. [Hint: use the line numbers on the left to refer to
a part of the code.]
1 def add_tx_mining(block):
2 difficulty=len(block)
3 chain=0
4 while chain 5 if block[chain ]==" ":
6 break
7 print(block[chain])
8 chain +=1
9 return "End"
10
11 add_tx_mining("West End")
What is its output? [6 marks]
3.3 Describe what the following script does. [Hint: use the line numbers on the left to refer to
a part of the code.]
1 import pandas as pd
2 fee =50
3 stones = pd.DataFrame ({"Paid": [250, 350, 200, 100],
4 "Volume": [5, 15, 5, 20]})
5 colors = ["Black","Green","Blue","Red"]
6 numbers = [1,2,3,4]
7 for i in range (4):
8 numbers[i] = colors[3-i]
9 stones["Color"] = numbers
10 stones["PPS"] = stones.apply(lambda x: (x["Paid"]-fee)/x["Volume"],axis
=1)
11 buy = stones["Color"] != "Red"
12 sell = stones["PPS"] > 10
13 trade = stones[buy&sell]
14 print(trade)
What is its output? [6 marks]
3.4 Your team is working on a tool that would estimate housing rental rates with high precision.
Your colleague has already built and trained a neural network model. However, the current
results are short of the desired precision and the colleague is considering an increase to the
number of neurons in one of the hidden layers of the model. Do you support this decision?
Explain. Is there another route of action that you can recommend?
[4 marks]
Question 3 continues on the next page: Please turn over
IB3M10 Page 7 of 7
3.5 Describe what the following script does. Note: it uses the variable stones from part 3.3
above. [Hint: use the line numbers on the left to refer to a part of the code.]
1 class chest():
2 def __init__(self , first , second = 5):
3 self.gems = first
4 self.worth = second
5 def value_gems(self):
6 print(self.gems.head(self.worth))
7 def count_gems(self):
8 print(self.gems["Volume"]. value_counts ())
9
10 coins = 1
11 my_gear = chest(stones , coins)
12 my_gear.value_gems ()
13 my_gear.count_gems ()
What is its output? [6 marks]
3.6 You would like to train a random forest model. For this, you have already i) collected the
data; ii) saved labels in the variable labels and features in the variable features; iii)
started working on the code:
1 from sklearn.ensemble import RandomForestRegressor
2 from sklearn.metrics import mean_squared_error as my_mse
3 ran_for = RandomForestRegressor(random_state =1)
Continue the code in order to train the model on your data and compute the value of the
loss function as mean squared errors. [Hint: this can be done in three lines of code.]
[4 marks]
3.7 You have trained a decision tree model and need to evaluate its performance. You compare
a value of the loss function for a training set with a value of the loss function for a validation
set and realize that the two di↵er significantly. Explain why this might be problematic
and describe what you can do to resolve the issue.
[3 marks]
[Total marks: 31]
END OF PAPER

essay、essay代写