Spaces:
Sleeping
Sleeping
Update course_recommender.py
Browse files20 unmodified lines21222324252696 unmodified lines1231241251261271281291301311321331341351361371381393 unmodified lines143144145146147148149150151152153154155171 unmodified lines32732832933020 unmodified linesself._last_data_count = 0 # Track data count for auto-retrainingself._auto_retrain_threshold = 5 # Retrain every 5 new feedbacksself._min_samples_for_training = 10 # Minimum samples needed to traindef preprocess_data(self, df: pd.DataFrame) -> pd.DataFrame:"""Preprocess the data for training"""96 unmodified linesdef check_and_auto_retrain(self):"""Check if enough new data exists and auto-retrain if needed"""current_count = self.get_current_data_count()if current_count < self._min_samples_for_training:print(f"Not enough data for training: {current_count} < {self._min_samples_for_training}")return Falseif current_count - self._last_data_count >= self._auto_retrain_threshold:print(f"Auto-retraining triggered: {current_count - self._last_data_count} new feedbacks")try:accuracy = self.train_model(use_database=True)self._last_data_count = current_countprint(f"Auto-retraining completed with accuracy: {accuracy:.3f}")return Trueexcept Exception as e:3 unmodified linesreturn Falsedef add_feedback_with_learning(self, course: str, stanine: int, gwa: float, strand: str,rating: int, hobbies: str) -> bool:"""Add feedback to database and trigger auto-learning if needed"""# Add feedback to databasesuccess = self.db_connection.add_feedback(course, stanine, gwa, strand, rating, hobbies)if success:print(f"Feedback added for course: {course}")# Check if we should auto-retrainself.check_and_auto_retrain()171 unmodified linesdef 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)20 unmodified lines2122232425262796 unmodified lines1241251261271281291301311321331341351361371381391401413 unmodified lines145146147148149150151152153154155156157158159160161162163164165166167168169170171171 unmodified lines34334434534620 unmodified linesself._last_data_count = 0 # Track data count for auto-retrainingself._auto_retrain_threshold = 5 # Retrain every 5 new feedbacksself._min_samples_for_training = 10 # Minimum samples needed to trainself._local_feedback = [] # Store feedback locally for learningdef preprocess_data(self, df: pd.DataFrame) -> pd.DataFrame:"""Preprocess the data for training"""96 unmodified linesdef check_and_auto_retrain(self):"""Check if enough new data exists and auto-retrain if needed"""# Use local feedback count for auto-retraininglocal_feedback_count = len(self._local_feedback)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 Falseif 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 = local_feedback_countprint(f"Auto-retraining completed with accuracy: {accuracy:.3f}")return Trueexcept Exception as e:3 unmodified linesreturn Falsedef add_feedback_with_learning(self, course: str, stanine: int, gwa: float, strand: str,rating: str, hobbies: str) -> bool:"""Add feedback to database and trigger auto-learning if needed"""# Add feedback to databasesuccess = 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-retrainself.check_and_auto_retrain()171 unmodified linesdef 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)
course_recommender.py+24-8