Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python ではじめるスパースモデリング

Python ではじめるスパースモデリング

Presentation slides at Hannnari Python #2
https://hannari-python.connpass.com/event/74633/

Hacarus Inc.

January 19, 2018
Tweet

More Decks by Hacarus Inc.

Other Decks in Technology

Transcript

  1. $50JTԿ • $IJFG5BMLJOH 0GGJDFS • ϋΧϧεͷ։ൃ੹೚ऀ • )BDBSVT 'JU৯ࣄ΍ӡಈʹج͍݈ͮͨ߁؅ཧαʔϏε •

    )"$"3649ػցֶशΛ༻͍ͨσʔλղੳαʔϏε • ೔ຊɺϑΟϦϐϯʹ໊ͷ։ൃϝϯόʔ
  2. ϋΧϧεͷٕज़ελοΫ • όοΫΤϯυɿ1ZUIPO 'MBTL42-"MDIFNZ • ϑϩϯτΤϯυ 3FBDU+4 • ϞόΠϧɿ4XJGU,PUMJO •

    Πϯϑϥɿ"84 1ZUIPO GBCSJDBOTJCMF • ػցֶशɿ1ZUIPO TDJLJUMFBSOKVQZUFS
  3. ଟ߲ࣜճؼ from sklearn.linear_model import LinearRegression, Lasso, OrthogonalMatchingPursuit from sklearn.preprocessing import

    PolynomialFeatures from sklearn.pipeline import make_pipeline poly_preprocess = PolynomialFeatures(poly_dim, include_bias=False) # models linear = LinearRegression() lasso = Lasso(alpha=0.002, max_iter=500000, tol=0.000001) omp = OrthogonalMatchingPursuit(n_nonzero_coefs=5) def fit_and_predict(predictor): model = make_pipeline(poly_preprocess, predictor) model.fit(x.reshape(-1, 1), y) y_predicted = model.predict(x.reshape(-1, 1)) t_predicted = model.predict(t.reshape(-1, 1)) return y_predicted, t_predicted
  4. ଟ߲ࣜճؼ • ελʔτ஍఺͸࠷খೋ৐๏ min 1 2 − 0 Z ͕ग़ྗɺX

    ͸ॏΈɺY ͸ೖྗ ্هΛຬͨ͢ X ΛٻΊΔ໰୊
  5. ଟ߲ࣜճؼ • աֶशΛ͚͞ΔͨΊʹਖ਼ଇԽ߲Λ௥Ճ min 1 2 − 0 + 2

    ॏΈ X Λখ͘͢͞Δ੍໿Λ͚ͭΔ͜ͱͰաֶशΛ཈੍ -ϊϧϜ -BTTPɾ-ϊϧϜ 3JEHF
  6. ଟ߲ࣜճؼ • ຊདྷղ͖͍ͨ -ϊϧϜ࠷దԽ min 1 2 − 0 +

    & -ϊϧϜ࠷దԽ͸૊߹ͤ࠷దԽ໰୊ /1ࠔ೉ ہॴతʹղ͘ᩦཉΞϧΰϦζϜ͕ .BUDIJOH1VSTVJU΍ *)5 ͳͲ
  7. ௿ϥϯΫߦྻ࠶ߏ੒ # initial guess X = np.random.rand(*A.shape) # retrieve existing

    values refill(X) for t in range(self.max_iter): # update threshold in each iteration thresh = self.alpha * (1 - t / self.max_iter) # apply SVD U, S, V = np.linalg.svd(X, full_matrices=False) # apply soft thresholding function to singular values S = soft_thresh(S, thresh) S = np.diag(S) # reconstruct X X = U.dot(S).dot(V) refill(X) return X