/
NonerCo
/
StudentSystem
Обзор
Документация
Войти
/
NonerCo
/
StudentSystem
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main.py
116 строк
4 KB
NonerCo
create src/main.py
13 янв 2026, 20:53
13 янв 2026, 20:53
8cb4f5f
Код
Авторство
О чём код?
""" Основной скрипт системы анализа успеваемости студентов. """ import argparse import json from datetime import datetime from pathlib import Path import pandas as pd import yaml from src.data_loader import load_and_preprocess_data from src.features import create_features from src.models import PerformancePredictor from src.analyzer import PerformanceAnalyzer from src.visualizer import create_dashboard_visualizations def main(config_path="config.yaml"): """Основная функция запуска анализа.""" # Загрузка конфигурации with open(config_path) as f: config = yaml.safe_load(f) print("=" * 50) print("Student Performance Analytics System") print(f"Started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print("=" * 50) # 1. Загрузка данных print("\n[1/5] Загрузка данных...") df = load_and_preprocess_data( config['data']['raw_path'], config['data']['preprocessing'] ) print(f" Загружено {len(df)} записей, {len(df.columns)} признаков") # 2. Создание признаков print("\n[2/5] Создание признаков...") X, y = create_features(df, config['features']) print(f" Создано {X.shape[1]} признаков") # 3. Обучение модели print("\n[3/5] Обучение модели...") predictor = PerformancePredictor( model_type=config['model']['type'], params=config['model']['params'] ) results = predictor.train_and_evaluate( X, y, test_size=config['model']['test_size'], random_state=config['model']['random_state'] ) # 4. Анализ результатов print("\n[4/5] Анализ результатов...") analyzer = PerformanceAnalyzer(predictor.model, X, y) feature_importance = analyzer.get_feature_importance() risk_students = analyzer.identify_risk_students(top_n=10) # 5. Визуализация print("\n[5/5] Создание визуализаций...") visualizations = create_dashboard_visualizations( df, results, feature_importance, risk_students ) # Сохранение результатов print("\n[✓] Сохранение результатов...") save_results(results, feature_importance, risk_students, config) # Вывод основных метрик print("\n" + "=" * 50) print("РЕЗУЛЬТАТЫ:") print(f"Модель: {config['model']['type']}") print(f"Точность: {results['accuracy']:.3f}") print(f"F1-score: {results['f1_score']:.3f}") print(f"Важнейший признак: {feature_importance.iloc[0]['feature']}") print(f"Студентов в группе риска: {len(risk_students)}") print("=" * 50) return results def save_results(results, feature_importance, risk_students, config): """Сохранение результатов анализа.""" results_dir = Path(config['data']['results_path']) results_dir.mkdir(exist_ok=True) timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") # 1. Сохранение метрик metrics_path = results_dir / f"metrics_{timestamp}.json" with open(metrics_path, 'w') as f: json.dump(results, f, indent=2) # 2. Сохранение важности признаков feature_path = results_dir / f"feature_importance_{timestamp}.csv" feature_importance.to_csv(feature_path, index=False) # 3. Сохранение студентов в группе риска risk_path = results_dir / f"risk_students_{timestamp}.csv" risk_students.to_csv(risk_path, index=False) print(f" Результаты сохранены в {results_dir}/") if __name__ == "__main__": parser = argparse.ArgumentParser(description="Student Performance Analytics") parser.add_argument("--config", type=str, default="config.yaml", help="Path to configuration file") args = parser.parse_args() main(args.config)