# emielstoelinga/ccmlwi architecture

> Architecture diagram of the GitHub repository emielstoelinga/ccmlwi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emielstoelinga/ccmlwi
- Repository: https://github.com/emielstoelinga/ccmlwi

## Overview

##### Project Type and Purpose
- This is a research-oriented stock-market prediction tool that ingests news-headline datasets, runs two modeling approaches (sentiment-analysis + SVM and LSTM networks), evaluates results, and optionally exposes a simple web UI for demonstration.

##### Main Architectural Components
a. Data Ingestion & Storage
- Combine_Data.py & the various Jupyter notebooks (Bag_of_words.ipynb, Combine_Data*.ipynb) collect and merge CSV/Kaggle news-headline and stock-value datasets.
- Raw data files (CSV/JSON) live in the project root or subfolders like “baseline”, “predictionBySentiment”, “sentimentPerHeadline”.
b. Preprocessing & Feature Extraction
- Scripts under RNN/data.py and LSTM/tf_data.py clean text, build vocabulary (top 2k words), compute embeddings or bag-of-words, and calculate sentiment scores (using NLTK’s VADER in sentimentPerHeadline.py).
- The baseline module (baseline/baseline.py) implements a trivial classifier for comparison.
c. Modeling Pipelines
- Sentiment-analysis pipeline:
- predictionBySentiment/*.py filter company-specific headlines, compute sentiment features, invoke scikit-learn SVMs to train/test.
- sentimentPerHeadline/sentimentPerHeadline.py computes per-headline sentiment.
- LSTM pipeline:
- LSTM/tf_train.py defines the CNN+LSTM architecture;
- LSTM/tf_test.py runs evaluation on held-out data;
- LSTM/tf_data.py feeds tokenized, padded sequences into tf_train.
- RNN pipeline (alternative to LSTM):
- RNN/model.py, RNN/train.py orchestrate a vanilla RNN classifier.
d. Evaluation & Reporting
- Data+Exploration.py and notebooks plot accuracies, generate tables (Tables 1 & 2).
e. Web Interface (optional)
- Web/main.py implements a Flask app that invokes selected models and renders results via Web/templates/index.html.

##### Component Interactions
- From Combine_Data → Preprocessing modules (tokenization, sentiment scoring)
- From Preprocessing → Model Trainers (SVM, RNN, LSTM)
- From Trainers → Evaluation & Results (plots, tables)
- From Results → Web UI (if deployed)
- External dependencies (NLTK, scikit-learn, TensorFlow/Keras) callouts on each relevant module.

##### Architectural Patterns & Principles
- Modular pipeline: separate data, preprocess, train, test, and serve phases.
- Reusability: sentiment and tokenization code used by both SVM and neural nets.
- MVC in the Web folder (Flask controller, template view, model invocation).
- Batch processing (no streaming or real-time inference).

##### Technologies & Libraries
- Python 3.x, Jupyter notebooks
- scikit-learn (SVM classifiers)
- NLTK (VADER sentiment)
- TensorFlow/Keras (CNN+LSTM, RNN)
- Flask (Web interface)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources
    subgraph "Data Sources"
        direction TB
        KaggleAPI(("Kaggle API")):::ext
        RawData(["Raw Datasets"]):::datastore
    end

    %% Data Ingestion
    subgraph "Data Ingestion & Storage"
        direction TB
        CombineData(["Combine_Data"]):::process
        NB1(["Bag_of_words.ipynb"]):::process
        NB2(["Combine_Data.ipynb"]):::process
        NB3(["Combine_Data_Microsoft_Only.ipynb"]):::process
    end

    %% Preprocessing & Feature Extraction
    subgraph "Preprocessing & Feature Extraction"
        direction TB
        Pre_RNN(["Preprocessor RNN"]):::ml
        Pre_LSTM(["Preprocessor LSTM"]):::ml
        SentimentScorer(["Sentiment Scorer"]):::ml
        BaselineFE(["Baseline Feature Extractor"]):::ml
    end

    %% Modeling Pipelines
    subgraph "Modeling Pipelines"
        direction TB
        subgraph "Sentiment-Analysis Pipeline"
            direction TB
            SHeadline(["Per-Headline Sentiment"]):::ml
            subgraph "SVM Trainers"
                direction TB
                GTech(["googleAndTechRowsOnGoogle.py"]):::ml
                IBTech(["ibmAndTechRowsOnIBM.py"]):::ml
                MTech(["microsoftAndTechRowsOnMicrosoft.py"]):::ml
                OnlyG(["onlyGoogleRowsOnGoogle.py"]):::ml
                OnlyI(["onlyIBMRowsOnIBM.py"]):::ml
                OnlyM(["onlyMicrosoftRowsOnMicrosoft.py"]):::ml
            end
        end
        subgraph "LSTM Pipeline"
            direction TB
            LData(["LSTM Data Feeder"]):::ml
            LTrain(["LSTM Trainer"]):::ml
            LTest(["LSTM Tester"]):::ml
        end
        subgraph "RNN Pipeline"
            direction TB
            RModel(["RNN Model"]):::ml
            RTrain(["RNN Trainer"]):::ml
        end
    end

    %% Evaluation & Reporting
    Evaluator(["Evaluator & Reporter"]):::process
    ArchitectureImg(["architecture.png"]):::process

    %% Web Interface
    subgraph "Web Interface"
        direction TB
        FlaskApp(["Flask App"]):::web
        Template(["index.html"]):::web
    end

    %% Connections
    KaggleAPI -->|"download datasets"| RawData
    RawData -->|"raw files"| CombineData
    CombineData -->|"cleaned data"| Pre_RNN
    CombineData --> Pre_LSTM
    CombineData --> SentimentScorer
    CombineData --> BaselineFE

    Pre_RNN -->|"tokenized sequences"| RModel
    Pre_RNN --> RTrain
    Pre_LSTM --> LData
    LData --> LTrain
    LTrain --> LTest
    SentimentScorer --> SHeadline
    SHeadline --> GTech
    SHeadline --> IBTech
    SHeadline --> MTech
    SHeadline --> OnlyG
    SHeadline --> OnlyI
    SHeadline --> OnlyM
    BaselineFE --> Evaluator

    GTech --> Evaluator
    IBTech --> Evaluator
    MTech --> Evaluator
    OnlyG --> Evaluator
    OnlyI --> Evaluator
    OnlyM --> Evaluator
    LTest --> Evaluator
    RTrain --> Evaluator

    Evaluator -->|"accuracy metrics"| FlaskApp
    FlaskApp --> Template

    %% Click Events
    click CombineData "https://github.com/emielstoelinga/ccmlwi/blob/master/Combine_Data.py"
    click NB1 "https://github.com/emielstoelinga/ccmlwi/blob/master/Bag_of_words.ipynb"
    click NB2 "https://github.com/emielstoelinga/ccmlwi/blob/master/Combine_Data.ipynb"
    click NB3 "https://github.com/emielstoelinga/ccmlwi/blob/master/Combine_Data_Microsoft_Only.ipynb"
    click Pre_RNN "https://github.com/emielstoelinga/ccmlwi/blob/master/RNN/data.py"
    click Pre_LSTM "https://github.com/emielstoelinga/ccmlwi/blob/master/LSTM/tf_data.py"
    click SentimentScorer "https://github.com/emielstoelinga/ccmlwi/blob/master/sentimentPerHeadline/sentimentPerHeadline.py"
    click BaselineFE "https://github.com/emielstoelinga/ccmlwi/blob/master/baseline/baseline.py"
    click GTech "https://github.com/emielstoelinga/ccmlwi/blob/master/predictionBySentiment/googleAndTechRowsOnGoogle.py"
    click IBTech "https://github.com/emielstoelinga/ccmlwi/blob/master/predictionBySentiment/ibmAndTechRowsOnIBM.py"
    click MTech "https://github.com/emielstoelinga/ccmlwi/blob/master/predictionBySentiment/microsoftAndTechRowsOnMicrosoft.py"
    click OnlyG "https://github.com/emielstoelinga/ccmlwi/blob/master/predictionBySentiment/onlyGoogleRowsOnGoogle.py"
    click OnlyI "https://github.com/emielstoelinga/ccmlwi/blob/master/predictionBySentiment/onlyIBMRowsOnIBM.py"
    click OnlyM "https://github.com/emielstoelinga/ccmlwi/blob/master/predictionBySentiment/onlyMicrosoftRowsOnMicrosoft.py"
    click LData "https://github.com/emielstoelinga/ccmlwi/blob/master/LSTM/tf_data.py"
    click LTrain "https://github.com/emielstoelinga/ccmlwi/blob/master/LSTM/tf_train.py"
    click LTest "https://github.com/emielstoelinga/ccmlwi/blob/master/LSTM/tf_test.py"
    click RModel "https://github.com/emielstoelinga/ccmlwi/blob/master/RNN/model.py"
    click RTrain "https://github.com/emielstoelinga/ccmlwi/blob/master/RNN/train.py"
    click Evaluator "https://github.com/emielstoelinga/ccmlwi/blob/master/Data+Exploration.py"
    click ArchitectureImg "https://github.com/emielstoelinga/ccmlwi/blob/master/report/architecture.png"
    click FlaskApp "https://github.com/emielstoelinga/ccmlwi/blob/master/Web/main.py"
    click Template "https://github.com/emielstoelinga/ccmlwi/blob/master/Web/templates/index.html"

    %% Styles
    classDef datastore fill:#a2d39c,stroke:#333,stroke-width:1px
    classDef ml fill:#6cb4ee,stroke:#333,stroke-width:1px
    classDef web fill:#f4a261,stroke:#333,stroke-width:1px
    classDef ext fill:#cccccc,stroke:#333,stroke-width:1px
    classDef process fill:#ddd,stroke:#333,stroke-width:1px
```
