-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrule_based_class.py
More file actions
170 lines (151 loc) · 9.19 KB
/
Copy pathrule_based_class.py
File metadata and controls
170 lines (151 loc) · 9.19 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import pandas as pd
import re
category_to_subclusters = {
'Apprenticeships, Internships, Placements': {
'Apprentice & Trainee Schemes': ['apprenticeship', 'apprenticeships', 'trainee', 'scheme', 'schemes'],
'Internships & Placements': ['internship', 'internships', 'placement', 'placements', 'work', 'experience', 'student'],
'Development of Opportunities': ['develop', 'opportunities', 'offer', 'explore', 'create']
},
'Career Frameworks & Role Definition': {
'Role Profiles & Job Families': ['role', 'roles', 'profiles', 'job', 'families', 'define', 'definition'],
'Career Framework & Structure': ['framework', 'structure', 'map', 'mapping', 'pathways'],
'Review & Alignment': ['review', 'align', 'grade', 'grading', 'benchmark']
},
'Career Pathways & Progression': {
'Promotion & Progression Routes': ['promotion', 'progression', 'pathway', 'pathways', 'advancement'],
'Career Development & Opportunities': ['career', 'development', 'opportunities', 'develop'],
'Guidance & Support': ['support', 'mentoring', 'guidance', 'review', 'appraisal']
},
'Data & Workforce Analysis': {
'Data Collection & Mapping': ['data', 'mapping', 'workforce', 'collect', 'analysis', 'understand'],
'Surveys & Feedback': ['survey', 'surveys', 'feedback', 'pulse', 'culture'],
'Skills Analysis': ['skills', 'skill', 'audit', 'needs', 'capability']
},
'EDI (Equality, Diversity & Inclusion)': {
'EDI Initiatives & Strategy': ['edi', 'equality', 'diversity', 'inclusion', 'strategy', 'action', 'plan'],
'Support & Working Groups': ['group', 'network', 'support', 'champions', 'working'],
'Monitoring & Promotion': ['promote', 'monitor', 'ensure', 'fair', 'transparent', 'inclusive']
},
'External Collaboration & Partnerships': {
'Engagement with External Partners': ['external', 'partners', 'collaborate', 'collaboration', 'stakeholders', 'industry'],
'Regional & National Networks': ['networks', 'regional', 'national', 'uk', 'midlands', 'talent'],
'Sharing Best Practice': ['sharing', 'practice', 'share', 'showcase', 'knowledge']
},
'Funding for Technicians': {
'Securing Internal Funding': ['funding', 'fund', 'budget', 'resource', 'financial', 'support', 'central'],
'External Funding Opportunities': ['external', 'grants', 'opportunities', 'bids', 'applications'],
'Sustainability & Costing': ['sustainability', 'costing', 'recharging', 'sustainable', 'model']
},
'Mentorship & Support': {
'Mentoring Schemes': ['mentoring', 'mentor', 'mentors', 'scheme', 'schemes', 'programme'],
'Coaching & Guidance': ['coaching', 'coach', 'guidance', 'buddy', 'peer'],
'Support Networks': ['support', 'network', 'networks', 'community', 'groups']
},
'Monitoring & Evaluation of TC': {
'Progress Monitoring & Reporting': ['monitor', 'progress', 'evaluation', 'report', 'track', 'measure'],
'Action Plan Management': ['action', 'plan', 'review', 'delivery', 'actions', 'objectives'],
'Surveys & Metrics': ['survey', 'surveys', 'metrics', 'kpis', 'data', 'baseline']
},
'Networking and Presenting': {
'Networking Events & Conferences': ['network', 'networking', 'events', 'conference', 'forum', 'symposium'],
'Showcasing & Presenting': ['present', 'presenting', 'showcase', 'opportunities', 'posters', 'talks'],
'Community Building': ['community', 'communities', 'practice', 'groups', 'connect']
},
'Ongoing Visibility & Communication': {
'Internal Communications': ['communications', 'comms', 'newsletter', 'internal', 'channels', 'bulletin'],
'Website & Online Profiles': ['website', 'online', 'profiles', 'web', 'webpages', 'digital'],
'Promotion & Case Studies': ['promote', 'promotion', 'visibility', 'case', 'studies', 'highlight', 'showcase']
},
'Professional Registration & Accreditation': {
'Promotion of Registration': ['professional', 'registration', 'promote', 'encourage', 'promotion'],
'Support & Mentorship for Registration': ['support', 'mentors', 'champions', 'workshops', 'cohorts', 'guidance'],
'Funding & Financial Support': ['funding', 'fund', 'fees', 'financial', 'costs', 'reimburse']
},
'Recognition & Awards': {
'Awards & Recognition Schemes': ['awards', 'award', 'recognition', 'scheme', 'schemes', 'ceremony'],
'Celebrating Success': ['celebrate', 'success', 'excellence', 'contribution', 'achievements'],
'Promotion of Recognition': ['promote', 'raise', 'profile', 'ensure', 'recognise']
},
'Recruitment & Onboarding': {
'Recruitment Processes': ['recruitment', 'recruiting', 'adverts', 'job', 'selection', 'hiring'],
'Induction & Onboarding': ['induction', 'onboarding', 'welcome', 'new', 'starters'],
'Improving Diversity in Recruitment': ['edi', 'diversity', 'inclusive', 'fair', 'transparent']
},
'Representation in Institutional Governance': {
'Committee Representation': ['representation', 'committee', 'committees', 'groups', 'meetings'],
'Voice & Influence': ['voice', 'involved', 'involvement', 'input', 'consultation'],
'Policy & Decision Making': ['policy', 'decision', 'making', 'governance', 'strategy']
},
'Technician Leadership': {
'Leadership Development': ['leadership', 'development', 'programme', 'skills', 'training'],
'Management & Senior Roles': ['management', 'leaders', 'senior', 'managers', 'lead'],
'Empowerment & Influence': ['empower', 'strategic', 'influence', 'voice', 'opportunities']
},
'Technician Voice & Feedback': {
'Feedback Mechanisms': ['feedback', 'voice', 'forums', 'channels', 'mechanisms', 'listen'],
'Surveys & Consultations': ['survey', 'surveys', 'consult', 'consultation', 'engagement'],
'Representation & Advocacy': ['representation', 'representative', 'advocacy', 'champions', 'network']
},
'Training & Skills Development': {
'Training Needs & Skills Audit': ['training', 'skills', 'development', 'needs', 'audit', 'analysis'],
'Development Opportunities & Workshops': ['opportunities', 'workshops', 'courses', 'access', 'provide', 'sessions'],
'Personal Development Plans (PDP)': ['pdp', 'pdps', 'personal', 'development', 'planning', 'review']
}
}
# =====================================================================================
def assign_subcluster_name(statement, subcluster_definitions):
"""
Assigns a statement to a predefined sub-cluster based on keyword matching.
"""
# Clean the statement to ensure better matching
statement_lower = statement.lower()
# Use a dictionary to store the match count for each sub-cluster
scores = {name: 0 for name in subcluster_definitions.keys()}
# Tally the scores
for name, keywords in subcluster_definitions.items():
for keyword in keywords:
# Use regex to find whole words to avoid matching parts of words (e.g., 'art' in 'department')
if re.search(r'\b' + re.escape(keyword) + r'\b', statement_lower):
scores[name] += 1
# Find the sub-cluster with the highest score. If all scores are 0, it will return 'Unassigned'
max_score = 0
best_match = 'Unassigned'
for name, score in scores.items():
if score > max_score:
max_score = score
best_match = name
return best_match
# --- Main Script Execution ---
try:
df = pd.read_csv('Actions_FinalData - All_Data.csv')
# Prepare a list to hold the results
all_results = []
print("Starting classification based on predefined sub-clusters...")
# Loop through each unique category from the dataframe
for category_name in df['Categories'].unique():
print(f"Processing Category: '{category_name}'")
# Filter the dataframe for the current category
category_df = df[df['Categories'] == category_name].copy()
# Check if we have defined sub-clusters for this category
if category_name in category_to_subclusters:
# Get the definitions for the current category
subcluster_defs = category_to_subclusters[category_name]
# Apply the classification function to each statement
category_df['predefined_subcluster'] = category_df['Extracted Action'].apply(
lambda x: assign_subcluster_name(x, subcluster_defs)
)
else:
# If no definitions exist, mark all as 'Not Defined'
category_df['predefined_subcluster'] = 'Not Defined'
all_results.append(category_df)
# Combine all processed dataframes back into one
final_df = pd.concat(all_results, ignore_index=True)
# Save the final results to a new CSV file
output_filename = 'named_subcluster_analysis.csv'
final_df.to_csv(output_filename, index=False)
print("\nClassification complete!")
print(f"All results have been saved to '{output_filename}'")
except FileNotFoundError:
print("Error: The file 'Actions_FinalData - All_Data.csv' was not found.")
except Exception as e:
print(f"An error occurred: {e}")