Skip to content

Commit

Permalink
chang module name
Browse files Browse the repository at this point in the history
  • Loading branch information
yxiaoli committed Jul 31, 2018
1 parent de59caf commit c879567
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
43 changes: 43 additions & 0 deletions npfeintool/PFA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Module for Principal Feature Analysis
PFA method
"""
from nptdms import TdmsFile
from sklearn import preprocessing
import pandas as pd
import numpy as np
#from sklearn.decomposition import PCA
from sklearn.cluster import KMeans
from collections import defaultdict
#from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
import seglearn as sgl
from matplotlib.mlab import PCA
import math

class PFA(object):
def __init__(self, n_features, q=None):
self.q = q
self.n_features = n_features

def fit(self, X):
if not self.q:
self.q = X.shape[1]

sc = StandardScaler()
X = sc.fit_transform(X)

pca = PCA(n_components=self.q).fit(X)
A_q = pca.components_.T

kmeans = KMeans(n_clusters=self.n_features).fit(A_q)
clusters = kmeans.predict(A_q)
cluster_centers = kmeans.cluster_centers_

dists = defaultdict(list)
for i, c in enumerate(clusters):
dist = euclidean_distances([A_q[i, :]], [cluster_centers[c, :]])[0][0]
dists[c].append((i, dist))

self.indices_ = [sorted(f, key=lambda x: x[1])[0][0] for f in dists.values()]
self.features_ = X[:, self.indices_]
5 changes: 5 additions & 0 deletions npfeintool/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

"""
The __init__.py file is usually empty, but if you remove the __init__.py file, Python will no longer look for submodules inside that directory.
"""
# Export public objects

0 comments on commit c879567

Please sign in to comment.