This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Mappable { | |
implicit class ToMapOps[A](val a: A) extends AnyVal { | |
import shapeless._ | |
import ops.record._ | |
def toMap[L <: HList](implicit | |
gen: LabelledGeneric.Aux[A, L], | |
tmr: ToMap[L] | |
): Map[String, Any] = { | |
val m: Map[tmr.Key, tmr.Value] = tmr(gen.to(a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def varianceSelection(X, THRESHOLD = .95): | |
sel = VarianceThreshold(threshold=(THRESHOLD * (1 - THRESHOLD))) | |
sel.fit_transform(X) | |
return X[[c for (s, c) in zip(sel.get_support(), X.columns.values) if s]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def fillWithMean(df): | |
return df.fillna(df.mean()).dropna(axis=1, how='all') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn | |
from sklearn.cluster import KMeans | |
import numpy as np | |
from scipy.spatial.distance import cdist, pdist | |
def elbow(df, n): | |
kMeansVar = [KMeans(n_clusters=k).fit(df.values) for k in range(1, n)] | |
centroids = [X.cluster_centers_ for X in kMeansVar] |
NewerOlder