Spaces:
Sleeping
Sleeping
Update course_recommender.py
Browse files20 unmodified lines2122232425262796 unmodified lines1241251261261271281291281291301311321331321331341351361371361381391401413 unmodified lines145146147146148149150151152153154155156157158159160161162163164165166167168169170171171 unmodified lines34334434533034620 unmodified lines self._last_data_count = 0 # Track data count for auto-retraining self._auto_retrain_threshold = 5 # Retrain every 5 new feedbacks self._min_samples_for_training = 10 # Minimum samples needed to train self._local_feedback = [] # Store feedback locally for learning def preprocess_data(self, df: pd.DataFrame) -> pd.DataFrame: """Preprocess the data for training"""96 unmodified lines def check_and_auto_retrain(self): """Check if enough new data exists and auto-retrain if needed""" current_count = self.get_current_data_count() # Use local feedback count for auto-retraining local_feedback_count = len(self._local_feedback) if current_count < self._min_samples_for_training: print(f"Not enough data for training: {current_count} < {self._min_samples_for_training}") if local_feedback_count < self._min_samples_for_training: print(f"Not enough local feedback for training: {local_feedback_count} < {self._min_samples_for_training}") return False if current_count - self._last_data_count >= self._auto_retrain_threshold: print(f"Auto-retraining triggered: {current_count - self._last_data_count} new feedbacks") if local_feedback_count - self._last_data_count >= self._auto_retrain_threshold: print(f"Auto-retraining triggered: {local_feedback_count - self._last_data_count} new local feedbacks") try: accuracy = self.train_model(use_database=True) self._last_data_count = current_count self._last_data_count = local_feedback_count print(f"Auto-retraining completed with accuracy: {accuracy:.3f}") return True except Exception as e:3 unmodified lines return False def add_feedback_with_learning(self, course: str, stanine: int, gwa: float, strand: str, rating: int, hobbies: str) -> bool: rating: str, hobbies: str) -> bool: """Add feedback to database and trigger auto-learning if needed""" # Add feedback to database success = self.db_connection.add_feedback(course, stanine, gwa, strand, rating, hobbies) if success: print(f"Feedback added for course: {course}") # Store feedback locally for learning (since API has issues) feedback_record = { 'course': course, 'stanine': stanine, 'gwa': gwa, 'strand': strand, 'rating': rating, 'hobbies': hobbies, 'count': 1 } self._local_feedback.append(feedback_record) print(f"Feedback stored locally for learning: {len(self._local_feedback)} total") # Check if we should auto-retrain self.check_and_auto_retrain() 171 unmodified lines def add_feedback(self, course: str, stanine: int, gwa: float, strand: str, rating: int, hobbies: str) -> bool: """Add user feedback to the database""" return self.db_connection.add_feedback(course, stanine, gwa, strand, rating, hobbies) return self.db_connection.add_feedback(course, stanine, gwa, strand, rating, hobbies)course_recommender.py+24-8