Skip to content

Instantly share code, notes, and snippets.

View vpekar's full-sized avatar

Viktor Pekar vpekar

View GitHub Profile
@vpekar
vpekar / pttest.py
Last active July 7, 2023 13:13
A Python implementation of the Directional Accuracy Score and Pesaran-Timmermann statistic.
import numpy as np
import scipy.stats as stats
def pttest(y, yhat):
"""Given NumPy arrays with predictions and with true values,
return Directional Accuracy Score, Pesaran-Timmermann statistic and its p-value
"""
size = y.shape[0]
pyz = np.sum(np.sign(y) == np.sign(yhat))/size
@vpekar
vpekar / Darkmatter2.sublime-color-scheme
Created March 16, 2023 00:04
A slightly modified JSON version of Darkmatter colour scheme for Sublime Text 4, based on https://github.com/patrickemuller/Sublime-Darkmatter-Theme
{
"name": "Darkmatter2",
"globals":
{
"background": "#14191f",
"caret": "#F8F8F0",
"foreground": "#aec2e0",
"invisibles": "#3B3A32",
"lineHighlight": "#1b232c",
"selection": "#183c66",
@vpekar
vpekar / macroaveraged_error_rates.py
Last active January 24, 2023 12:30
A Python implementation of Macroaveraged MAE and RMSE
"""Macroaveraged MAE and RMSE ([Baccianella et al 2009](http://nmis.isti.cnr.it/sebastiani/Publications/ISDA09.pdf)) for evaluation of ordinal classifiers.
"""
import numpy as np
def groupby_labels(y, yhat):
"""Based on https://stackoverflow.com/questions/38013778/is-there-any-numpy-group-by-function
"""
@vpekar
vpekar / plot_compare_reduction.py
Created November 3, 2016 13:27
Comparing feature selection methods including information gain and information gain ratio
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
=================================================================
Selecting dimensionality reduction with Pipeline and GridSearchCV
=================================================================
This example constructs a pipeline that does dimensionality
reduction followed by prediction with a support vector
classifier. It demonstrates the use of GridSearchCV and
@vpekar
vpekar / document_classification_20newsgroups.py
Last active March 13, 2017 05:55
Document classification with feature selection using information gain
"""
======================================================
Classification of text documents using sparse features
======================================================
This is an example showing how scikit-learn can be used to classify documents
by topics using a bag-of-words approach. This example uses a scipy.sparse
matrix to store the features and demonstrates various classifiers that can
efficiently handle sparse matrices.