Skip to content

Instantly share code, notes, and snippets.

View Killavus's full-sized avatar

Marcin Grzywaczewski Killavus

  • Wrocław, Poland
View GitHub Profile
from fuel.datasets.cifar10 import CIFAR10
from sklearn.cluster import KMeans
from collections import Counter
from scipy.stats.mstats import mode
import numpy as np
def PerformKMeansAnalysis(train_data, train_labels, test_data, test_labels):
naive_grouping = KMeans(n_clusters=10, n_init=5, n_jobs=8)
naive_grouping.fit(train_data)
For label 0: 0.865175145618
Representative: [ 0.]
======
For label 1: 0.869355945887
Representative: [ 6.]
======
For label 2: 0.828103005511
Representative: [ 0.]
======
For label 3: 0.886468632048
For label 0: 0.867669753086
For label 1: 0.82792603512
For label 2: 0.878846730532
For label 3: 0.795057662006
For label 4: 0.886658781769
For label 5: 0.882785618599
For label 6: 0.840796804795
For label 7: 0.864856124316
For label 8: 0.869239583546
For label 9: 0.877142283582
from collections import Counter
for label in set(group_labels):
train_mask = group_labels == label
real_labels = train_labels[train_mask]
pos_stat = Counter(real_labels).values()
# pos_stat is info about quantity of each label - as a list of quantities
const loginUnsuccessful = this.state.alert === "User Not Found";
classNames("alert", "alert-dismissable", {
"alert-danger": loginUnsuccessful
"alert-success": !loginUnsuccessful
});
# M1 (N x A) -> M2 (N x B) -> DM (A x B)
def ComputeDistanceMatrix(M1, M2):
# For each r-th row: Sum(k = 1, N) M1(r, k) ** 2
SM1 = np.sum(M1 ** 2)
# For each r-th row: Sum(k = 1, N) M2(r, k) ** 2
SM2 = np.sum(M2 ** 2)
# The last term: 2 * (M1 x M2^T)
M1M2_2 = 2 * np.dot(M1, M2.T)
def iteratorAtomsDepleted(iteratorAtoms):
return all(map(lambda iteratorAtom: iteratorAtom[1], iteratorAtoms))
def combine(*args):
listIterators = [[iter(passedList), False] for passedList in args]
result = []
while (not iteratorAtomsDepleted(listIterators)):
for index, iteratorAtom in enumerate(listIterators):
try:
iterator, alreadyDone = iteratorAtom
class PrepareCalculationForB2BManager
def prepare(quotation)
CalculationForB2BManager.new(
quotation.yearly_premium_value,
quotation.yearly_offer_number,
quotation.yearly_premium_url,
quotation.position_in_leads,
quotation.token,
quotation.save_quote_key,
quotation.competitors
@Killavus
Killavus / emptyFnLeverageExample.js
Created September 20, 2015 20:49
Processing graph-data. Each of node has a type. I leverage this knowledge to not 'ask', but tell what I want to do.
function emptyFn() {}
function matchNode(node, typeFunctions) {
return (typeFunctions[node.type] || emptyFn)(node);
}
// Example usage:
neighbourList.forEach(function(node) {
result = result.concat(
import React from 'react/addons';
import { DragDropContext, DragSource } from 'react-dnd';
import HTML5Backend from 'react-dnd/modules/backends/HTML5';
@DragDropContext(HTML5Backend)
class App extends React.Component {
render() {
return(
<div>