Skip to content

Commit

Permalink
after flu
Browse files Browse the repository at this point in the history
  • Loading branch information
SmirkCao committed Jun 6, 2019
1 parent 52b0575 commit a29bfec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CH17/lsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Filename: lsa
# Date: 6/03/19
# Author: 😏 <smirk dot cao at gmail dot com>
# 截断奇异值分解用在count/tf-idf矩阵的时候,叫做潜在语义分析。


class LSA(object):
def __init__(self, ):
pass
def __init__(self, n_components):
self.n_components = n_components
self.components = None

def fit(self, x):
pass
14 changes: 14 additions & 0 deletions CH17/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
# Ref to : https://code.visualstudio.com/docs/python/unit-testing
import unittest
from sklearn import datasets
from lsa import LSA as lsa_test
from sklearn.decomposition import TruncatedSVD as lsa_sklearn
import matplotlib.pyplot as plt
import numpy as np
import sys


class TestLSAMethods(unittest.TestCase):
Expand Down Expand Up @@ -73,3 +76,14 @@ def test_lsa_fig_1701(self):

print(40*"*"+"svh"+40*"*")
print(np.round(np.dot(s[:3]*np.eye(3), vh[:3, :]), 2))

def test_lsa_1701(self):
base_path = sys.path[0]
x = np.genfromtxt(base_path+"/data/data_1701.csv", delimiter=",")
# print(x)
lsa1 = lsa_sklearn(n_components=3)
rst = lsa1.fit_transform(x)
print("\n")
print("singular_values\n", lsa1.singular_values_)
print("components\n", lsa1.components_)
print("rst\n", rst)

0 comments on commit a29bfec

Please sign in to comment.