durrani commited on
Commit
2d62ac6
·
1 Parent(s): 28717bd
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Create the dataset
2
+ data = {
3
+ 'num_students': [500, 600, 700, 800, 900],
4
+ 'temperature': [20, 21, 22, 23, 24],
5
+ 'num_rooms': [30, 35, 40, 45, 50]
6
+ }
7
+
8
+ # Split the dataset into features (X) and target (y)
9
+ X = [[1, num_students, temperature] for num_students, temperature in zip(data['num_students'], data['temperature'])]
10
+ y = data['num_rooms']
11
+
12
+ # Calculate the coefficients using normal equations
13
+ XTX = [[sum(x[i] * x[j] for x in X) for j in range(len(X[0]))] for i in range(len(X[0]))]
14
+ XTy = [sum(X[i][j] * y[i] for i in range(len(X))) for j in range(len(X[0]))]
15
+
16
+ coefficients = [0] * len(X[0])
17
+ for i in range(len(X[0])):
18
+ coefficients[i] = sum(XTX[i][j] * XTy[j] for j in range(len(X[0])))
19
+
20
+ # Print the coefficients
21
+ print("Coefficients:", coefficients)
22
+
23
+ # Predict the number of rooms required for a new scenario
24
+ new_students = 750 # Number of students in the new scenario
25
+ new_temperature = 20 # Temperature in the new scenario
26
+
27
+ # Create the feature array for the new scenario
28
+ new_scenario = [1, new_students, new_temperature]
29
+
30
+ # Make the prediction
31
+ predicted_rooms = sum(coefficients[i] * new_scenario[i] for i in range(len(new_scenario)))
32
+
33
+ print("Number of students:", new_students)
34
+ print("Temperature:", new_temperature)
35
+ print("Predicted number of rooms:", predicted_rooms)