-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachine_learning_2.py
More file actions
73 lines (54 loc) · 1.86 KB
/
machine_learning_2.py
File metadata and controls
73 lines (54 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
BINARY CLASSIFICATION (NO TRAINING)
Goal:
Classify whether a student prefers group work (1)
or prefers solo work (0).
This version does NOT learn.
Weights are chosen manually.
"""
# ------------------------------------------------------------
# 1) ACTIVATION FUNCTION (Step Function)
# ------------------------------------------------------------
def step_activation(z):
if z >= 0:
return 1
else:
return 0
# ------------------------------------------------------------
# 2) COMPUTE RAW SCORE (z = w·x + b)
# ------------------------------------------------------------
def weighted_sum(features, weights, bias):
total = 0.0
for i in range(len(weights)):
total += features[i] * weights[i]
total += bias
return total
# ------------------------------------------------------------
# 3) PREDICT CATEGORY
# ------------------------------------------------------------
def predict(features, weights, bias):
z = weighted_sum(features, weights, bias)
return step_activation(z)
# ------------------------------------------------------------
# 4) MAIN PROGRAM
# ------------------------------------------------------------
def main():
# Features:
# [group_success_rate, solo_success_rate,
# speaks_in_groups_rate, chooses_group_when_free]
student = [0.80, 0.60, 0.70, 1]
# MANUALLY CHOSEN WEIGHTS
# We are encoding our assumptions:
# - Group success matters a lot (positive)
# - Solo success pushes toward solo preference (negative)
# - Speaking in groups matters
# - Choosing group when free matters a lot
weights = [2.0, -1.5, 1.2, 2.5]
# Bias shifts baseline tendency
bias = -1.0
prediction = predict(student, weights, bias)
print("Weights:", weights)
print("Bias:", bias)
print("Prediction (1=group, 0=solo):", prediction)
if __name__ == "__main__":
main()