<commit_before>package com.github;

import org.apache.log4j.Logger;

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

/**
 * Created by IntelliJ IDEA.
 * User: nirvdrum
 * Date: Aug 24, 2009
 * Time: 7:34:37 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main
{
  final static Logger log = Logger.getLogger(Main.class);

  public static void main(String[] args) throws IOException, ExecutionException, InterruptedException
  {
    log.info("Loading data.");
    final Map<String, Repository> repositories = DataLoader.loadRepositories();
    final DataSet data_set = DataLoader.loadWatchings();

    if (args.length > 0)
    {
      // Perform cross-validation.
      final List<DataSet> folds = data_set.stratify(1000);
      for (int i = 0; i < folds.size(); i++)
      {
        log.info(String.format("Starting fold %d.", i + 1));
        final DataSet test_set = folds.remove(0);
        final DataSet training_set = DataSet.combine(folds);

        log.info("Training");
        final NearestNeighbors knn = new NearestNeighbors(training_set);

        log.info("Classifying");
        final Map<String, Map<String, Collection<Float>>> evaluations = knn.evaluate(test_set.getWatchers().values());

        final Set<Watcher> prediction = NearestNeighbors.predict(knn, evaluations, 10, test_set.getWatchers());
        final Set<Watcher> all_predictions = NearestNeighbors.predict(knn, evaluations, 1000, test_set.getWatchers());

        analyze(test_set, training_set, prediction, all_predictions, knn, evaluations);

        log.info(String.format(">>> Results for fold %d: %f%% / %f%%", i + 1, NearestNeighbors.score(test_set, prediction) * 100, NearestNeighbors.score(test_set, all_predictions) * 100));

        folds.add(test_set);

        write_predictions(prediction);

        break;
      }<commit_msg>Run the full 10 folds for cross validation.<commit_after>package com.github;

import org.apache.log4j.Logger;

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

/**
 * Created by IntelliJ IDEA.
 * User: nirvdrum
 * Date: Aug 24, 2009
 * Time: 7:34:37 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main
{
  final static Logger log = Logger.getLogger(Main.class);

  public static void main(String[] args) throws IOException, ExecutionException, InterruptedException
  {
    log.info("Loading data.");
    final Map<String, Repository> repositories = DataLoader.loadRepositories();
    final DataSet data_set = DataLoader.loadWatchings();

    if (args.length > 0)
    {
      // Perform cross-validation.
      final List<DataSet> folds = data_set.stratify(10);
      for (int i = 0; i < folds.size(); i++)
      {
        log.info(String.format("Starting fold %d.", i + 1));
        final DataSet test_set = folds.remove(0);
        final DataSet training_set = DataSet.combine(folds);

        log.info("Training");
        final NearestNeighbors knn = new NearestNeighbors(training_set);

        log.info("Classifying");
        final Map<String, Map<String, Collection<Float>>> evaluations = knn.evaluate(test_set.getWatchers().values());

        final Set<Watcher> prediction = NearestNeighbors.predict(knn, evaluations, 10, test_set.getWatchers());
        final Set<Watcher> all_predictions = NearestNeighbors.predict(knn, evaluations, 1000, test_set.getWatchers());

        analyze(test_set, training_set, prediction, all_predictions, knn, evaluations);

        log.info(String.format(">>> Results for fold %d: %f%% / %f%%", i + 1, NearestNeighbors.score(test_set, prediction) * 100, NearestNeighbors.score(test_set, all_predictions) * 100));

        folds.add(test_set);

        write_predictions(prediction);
      }
{'fraction_non_alphanumeric': 0.12392077196546471, 'fraction_numerical': 0.01675977653631285, 'mean_word_length': 3.7515078407720144, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5812404', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1186, 'n_words': 294}