{"id":1472,"date":"2026-02-09T12:11:33","date_gmt":"2026-02-09T03:11:33","guid":{"rendered":"https:\/\/www.tsh-world.co.jp\/adv-rd\/?page_id=1472"},"modified":"2026-02-25T12:07:57","modified_gmt":"2026-02-25T03:07:57","slug":"column002","status":"publish","type":"page","link":"https:\/\/www.tsh-world.co.jp\/adv-rd\/labo\/column002\/","title":{"rendered":"LSTM AutoEncoder\u306b\u3088\u308b\u7570\u5e38\u691c\u77e5"},"content":{"rendered":"<section>\n<div class=\"inner\">\n<p><!--\n<img decoding=\"async\" style=\"border:2px solid #eee; width:100%;\" src=\"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-content\/uploads\/sites\/19\/h1_img_column_001.jpg\" alt=\"\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u90e8\u54c1\u8868\uff08SBOM\uff09\u306b\u3064\u3044\u3066\">\n\n\n<div class=\"column-author\">\n\u6771\u4eac\u30b7\u30b9\u30c6\u30e0\u30cf\u30a6\u30b9<br \/>\u5c71\u53e3\n<\/div>\n\n\n--><\/p>\n<h2>1. \u306f\u3058\u3081\u306b<\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Keras\u3067LSTM AutoEncoder\u3092\u5b9f\u88c5\u3057\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u7c21\u5358\u306a\u7570\u5e38\u691c\u77e5\u3092\u8a66\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>LSTM AutoEncoder\u3068\u306f<\/h3>\n<p>LSTM AutoEncoder\u306f\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u6271\u3044\u306b\u512a\u308c\u305fLSTM\uff08Long Short-Term Memory\uff09\u30e2\u30c7\u30eb\u3092\u7528\u3044\u305f\u30aa\u30fc\u30c8\u30a8\u30f3\u30b3\u30fc\u30c0\u3067\u3059\u3002\u4e3b\u306b\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u76e3\u8996\u3084\u8a2d\u5099\u306e\u4e88\u5146\u4fdd\u5168\u306a\u3069\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u7570\u5e38\u691c\u77e5\u306b\u6d3b\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u624b\u6cd5\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30b5\u30fc\u30d0\u904b\u7528\u8005\u3084\u30b7\u30b9\u30c6\u30e0\u7ba1\u7406\u8005\u306e\u4f5c\u696d\u8ca0\u8377\u3092\u8efd\u6e1b\u3057\u3001\u904b\u7528\u30b3\u30b9\u30c8\u306e\u524a\u6e1b\u306b\u3082\u3064\u306a\u304c\u308a\u307e\u3059\u3002<br \/>\nLSTM AutoEncoder\u306e\u4ed5\u7d44\u307f\u3068\u3057\u3066\u3001LSTM\u30e2\u30c7\u30eb\u3092\u524d\u5f8c\u306b\uff12\u3064\u4e26\u3079\u3066\u3044\u307e\u3059\u3002\u524d\u6bb5\u306eLSTM\uff08\u30a8\u30f3\u30b3\u30fc\u30c0\uff09\u304c\u30ed\u30b0\u3084\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u3092\u5727\u7e2e\u3057\u3001\u5f8c\u6bb5\u306eLSTM\uff08\u30c7\u30b3\u30fc\u30c0\uff09\u304c\u5fa9\u5143\u3057\u307e\u3059\u3002<br \/>\n\u6b63\u5e38\u306a\u30c7\u30fc\u30bf\u3067\u5b66\u7fd2\u3059\u308b\u305f\u3081\u3001\u6b63\u5e38\u30c7\u30fc\u30bf\u306e\u5fa9\u5143\u8aa4\u5dee\u306f\u5c0f\u3055\u304f\u306a\u308a\u307e\u3059\u304c\u3001\u30d1\u30bf\u30fc\u30f3\u304c\u7570\u306a\u308b\u7570\u5e38\u6642\u306f\u8aa4\u5dee\u304c\u5927\u304d\u304f\u306a\u308a\u307e\u3059\u3002\u6b63\u5e38\u30c7\u30fc\u30bf\u306e\u5fa9\u5143\u8aa4\u5dee\u3092\u57fa\u306b\u95be\u5024\u3092\u8a2d\u5b9a\u3057\u3066\u3084\u308c\u3070\u3001\u95be\u5024\u8d85\u904e\u3067\u7570\u5e38\u3092\u691c\u77e5\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>\u5b9f\u65bd\u5185\u5bb9<\/h3>\n<h4>1. \u5b66\u7fd2\u30c7\u30fc\u30bf\u306e\u751f\u6210<\/h4>\n<p>\u30fb\u5b66\u7fd2\u306b\u4f7f\u3046\u30c7\u30fc\u30bf\u306e\u751f\u6210\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\u30fb\u5b66\u7fd2\u306b\u4f7f\u7528\u3059\u308b\u30c7\u30fc\u30bf\u3068\u3057\u3066\u3001\u5468\u671f\u306e\u7570\u306a\u308bsin\u6ce2\u30921,000\u500b\u307b\u3069\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h4>2. \u30e2\u30c7\u30eb\u306e\u69cb\u7bc9\u3068\u5b66\u7fd2<\/h4>\n<p>\u30fb\u751f\u6210\u3057\u305f\u5b66\u7fd2\u30c7\u30fc\u30bf\u3092\u3082\u3068\u306b\u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3057\u307e\u3059\u3002<br \/>\n\u30fb\u5b66\u7fd2\u30c7\u30fc\u30bf\u3092\u30e2\u30c7\u30eb\u306b\u901a\u3057\u3001\u6b63\u3057\u304f\u5fa9\u5143\u3067\u304d\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h4>3. \u7570\u5e38\u30c7\u30fc\u30bf\u306e\u751f\u6210<\/h4>\n<p>\u30fb\u7570\u5e38\u691c\u77e5\u3092\u8a66\u3059\u305f\u3081\u306b\u3001\u7570\u5e38\u30c7\u30fc\u30bf\u306e\u751f\u6210\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\u30fb\u7570\u5e38\u691c\u77e5\u306b\u4f7f\u7528\u3059\u308b\u30c7\u30fc\u30bf\u3068\u3057\u3066\u3001sin\u6ce2\u306e\u4e00\u90e8\u5206\u306b+0.5\u3068-0.5\u3092\u4ea4\u4e92\u306b\u52a0\u7b97\u3057\u305f\u3082\u306e\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n\u30fb\u52a0\u7b97\u3057\u3066\u3044\u306a\u3044\u7bc4\u56f2\u306f\u6b63\u5e38\u3001\u6570\u5024\u3092\u52a0\u7b97\u3057\u305f\u7bc4\u56f2\u306f\u7570\u5e38\u3068\u3057\u3066\u6271\u3044\u307e\u3059\u3002<br \/>\n\u30fb\u7570\u5e38\u30c7\u30fc\u30bf\u3092\u30e2\u30c7\u30eb\u306b\u901a\u3057\u3001\u6b63\u3057\u304f\u5fa9\u5143\u3067\u304d\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h4>4. \u7570\u5e38\u691c\u77e5\u306e\u5b9f\u88c5<\/h4>\n<p>\u30fb\u7570\u5e38\u30c7\u30fc\u30bf\u3092\u6b63\u3057\u304f\u691c\u77e5\u3067\u304d\u308b\u3088\u3046\u95be\u5024\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u30fb\u8a2d\u5b9a\u3057\u305f\u95be\u5024\u3067\u7570\u5e38\u3092\u691c\u77e5\u3067\u304d\u308b\u304b\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>2. \u74b0\u5883<\/h2>\n<h3>\u30fb\u8a00\u8a9e\u304a\u3088\u3073\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30d0\u30fc\u30b8\u30e7\u30f3<\/h3>\n<p>\u3000Python version: 3.11.13<br \/>\n\u3000Keras version: 3.8.0<\/p>\n<p>&nbsp;<\/p>\n<h3>\u30fb\u5b9f\u884c\u74b0\u5883<\/h3>\n<p>\u3000Kaggle Notebook<br \/>\n\uff08\u8a18\u4e8b\u306b\u8a18\u8f09\u3057\u305f\u30b3\u30fc\u30c9\u30d6\u30ed\u30c3\u30af\u306fJupyter Notebook\u306e\u30bb\u30eb\u4e0a\u3067\u9806\u756a\u306b\u5b9f\u884c\u3059\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\uff09<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>3. \u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30dd\u30fc\u30c8<\/h2>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\nfrom keras.layers import Input, LSTM, RepeatVector, Dense<br \/>\nfrom keras.models import Model<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport numpy as np<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>4. \u5b66\u7fd2\u30c7\u30fc\u30bf\u306e\u751f\u6210<\/h2>\n<h3>\u30c7\u30fc\u30bf\u751f\u6210\u7528\u306e\u95a2\u6570<\/h3>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong># \u4eca\u56de\u4f7f\u3046\u30c7\u30fc\u30bf\uff081\u6b21\u5143\u306e\u30e9\u30f3\u30c0\u30e0\u5468\u671f\u306esin\u95a2\u6570\uff09\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306e\u95a2\u6570<\/strong><br \/>\ndef make_random_sin_data(num_patterns, timesteps):<br \/>\n<strong># \u6b63\u898f\u5206\u5e03\uff08\u5e73\u57471, \u6a19\u6e96\u504f\u5dee0.1\uff09\u306b\u5f93\u3046\u30e9\u30f3\u30c0\u30e0\u306a\u5468\u671f\u3092\u4f5c\u6210<\/strong><br \/>\nmean_period = 1.0<br \/>\nstd_dev_period = 0.1<br \/>\nperiods = np.random.normal(loc=mean_period, scale=std_dev_period, size=num_patterns)<br \/>\n<strong># \u884c\u5217\u3092\u521d\u671f\u5316<\/strong><br \/>\nmatrix = np.zeros((num_patterns, timesteps, 1))<br \/>\n<strong># \u5404\u30d1\u30bf\u30fc\u30f3\u306b\u5bfe\u3057\u3066sin\u95a2\u6570\u3092\u8a08\u7b97<\/strong><br \/>\nfor i in range(num_patterns):<br \/>\nx = np.linspace(0, 2 * np.pi, timesteps)<br \/>\nmatrix[i, :, 0] = np.sin(x \/ periods[i])<br \/>\nreturn matrix\n<\/p>\n<p>&nbsp;<\/p>\n<h3>\u30c7\u30fc\u30bf\u751f\u6210\u7528\u306e\u95a2\u6570<\/h3>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong># \u5b66\u7fd2\u30c7\u30fc\u30bf\u751f\u6210<\/strong><br \/>\nX_train = make_random_sin_data(1000,100)<br \/>\n<strong># \u30d7\u30ed\u30c3\u30c8\u306e\u6e96\u5099<\/strong><br \/>\nplt.figure(figsize=(10,5))<br \/>\n<strong># \u5404\u5b66\u7fd2\u30c7\u30fc\u30bf(sin\u6ce2)\u3092\u30d7\u30ed\u30c3\u30c8<\/strong><br \/>\nfor i in range(X_train.shape[0]):<br \/>\n    plt.plot(X_train[i, :, 0], alpha=0.5) # alpha\u3092\u6307\u5b9a\u3057\u3066\u900f\u660e\u5ea6\u8abf\u6574<br \/>\n<strong># \u30e9\u30d9\u30eb\u306e\u8a2d\u5b9a<\/strong><br \/>\nplt.xlabel(&#8216;timesteps&#8217;)<br \/>\nplt.ylabel(&#8216;value&#8217;)<br \/>\n<strong># \u30b0\u30e9\u30d5\u306e\u8868\u793a<\/strong><br \/>\nplt.show()<\/p>\n<p><center><img decoding=\"async\" src=\"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-content\/uploads\/sites\/19\/study_data.jpg\" \/><\/p>\n<p>\u5468\u671f\u306e\u7570\u306a\u308b1000\u500b\u306esin\u6ce2\u304c\u4eca\u56de\u306e\u5b66\u7fd2\u30c7\u30fc\u30bf\u3067\u3059\u3002<\/p>\n<p><\/center><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>5.  \u30e2\u30c7\u30eb\u306e\u69cb\u7bc9\u3068\u5b66\u7fd2<\/h2>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong># \u30d1\u30e9\u30e1\u30fc\u30bf\u8a2d\u5b9a<\/strong><br \/>\ntimesteps = 100<br \/>\ninput_dim = 1<br \/>\nlatent_dim = 10<br \/>\n<strong># \u30e2\u30c7\u30eb\u69cb\u7bc9<\/strong><br \/>\ninputs = Input(shape=(timesteps, input_dim))<br \/>\nencoded = LSTM(latent_dim, activation=&#8221;tanh&#8221;, return_sequences=False)(inputs)<br \/>\nhidden = RepeatVector(timesteps)(encoded)<br \/>\ndecoded = LSTM(latent_dim, activation=&#8221;tanh&#8221;, return_sequences=True)(hidden)<br \/>\ndecoded = Dense(input_dim, activation=&#8221;tanh&#8221;)(decoded)<br \/>\n<strong># \u30e2\u30c7\u30eb\u30b3\u30f3\u30d1\u30a4\u30eb<\/strong><br \/>\nautoencoder = Model(inputs, decoded)<br \/>\nautoencoder.compile(optimizer=&#8217;adam&#8217;, loss=&#8217;mse&#8217;)<br \/>\n<strong># \u30e2\u30c7\u30eb\u8a13\u7df4<\/strong><br \/>\nautoencoder.fit(X_train, X_train, epochs=30, batch_size=32, shuffle=True)<br \/>\n<strong># \u518d\u69cb\u7bc9\u30c7\u30fc\u30bf\u306e\u53d6\u5f97<\/strong><br \/>\nX_train_reconstructed = autoencoder.predict(X_train)<\/p>\n<p>&nbsp;<\/p>\n<h3>\u5b66\u7fd2\u30c7\u30fc\u30bf\u306e\u518d\u69cb\u7bc9\u7d50\u679c\u306e\u78ba\u8a8d<\/h3>\n<p>\u5b66\u7fd2\u30c7\u30fc\u30bf\u306esin\u6ce2\u306e1\u3064\u3068\u3001\u305d\u308c\u3092\u57fa\u306b\u518d\u69cb\u7bc9\u3057\u305f\u30c7\u30fc\u30bf\u3092\u540c\u6642\u306b\u4e26\u3079\u3066\u307f\u307e\u3059\u3002<\/p>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong># x\u8ef8\u306e\u30c7\u30fc\u30bf<\/strong><br \/>\nx = np.arange(1, 101)<br \/>\n<strong># y\u8ef8\u306e\u30c7\u30fc\u30bf\u30922\u3064\u7528\u610f<\/strong><br \/>\ny1 = X_train[0]<br \/>\ny2 = X_train_reconstructed[0]<br \/>\n<strong># \u30d7\u30ed\u30c3\u30c8\u306e\u4f5c\u6210<\/strong><br \/>\nplt.figure(figsize=(10, 5))<br \/>\n<strong># 1\u3064\u76ee\u306e\u30d7\u30ed\u30c3\u30c8<\/strong><br \/>\nplt.plot(x, y1, label=&#8217;train&#8217;, color=&#8217;b&#8217;)<br \/>\n<strong># 2\u3064\u76ee\u306e\u30d7\u30ed\u30c3\u30c8<\/strong><br \/>\nplt.plot(x, y2, label=&#8217;reconstructed&#8217;, color=&#8217;r&#8217;)<br \/>\n<strong># \u30e9\u30d9\u30eb\u306e\u8a2d\u5b9a<\/strong><br \/>\nplt.xlabel(&#8216;timesteps&#8217;)<br \/>\nplt.ylabel(&#8216;value&#8217;)<br \/>\n<strong># \u51e1\u4f8b\u306e\u8868\u793a<\/strong><br \/>\nplt.legend()<br \/>\n<strong># \u30b0\u30e9\u30d5\u306e\u8868\u793a<\/strong><br \/>\nplt.show()<\/p>\n<p><center><img decoding=\"async\" src=\"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-content\/uploads\/sites\/19\/result_check.png\" \/><\/p>\n<p>\u9752\u3044\u6ce2\u304c\u5b66\u7fd2\u30c7\u30fc\u30bf\u3001\u8d64\u3044\u6ce2\u304c\u305d\u308c\u3092\u57fa\u306b\u518d\u69cb\u7bc9\u3057\u305f\u30c7\u30fc\u30bf\u3067\u3059\u3002<\/p>\n<p><\/center><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>6. \u7570\u5e38\u30c7\u30fc\u30bf\u306e\u751f\u6210<\/h2>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong># \u5468\u671f\u30e9\u30f3\u30c0\u30e0\u306asin\u6ce2\u30921\u3064\u751f\u6210\uff08\u8981\u7d20\u6570\u306f100\uff09<\/strong><br \/>\nX_test = make_random_sin_data(1,100)<br \/>\n<strong># 50\u500b\u76ee\u306e\u8981\u7d20\u304b\u308959\u500b\u76ee\u306e\u8981\u7d20\u307e\u3067\u306b0.5\u3068-0.5\u3092\u4ea4\u4e92\u306b\u52a0\u7b97<\/strong><br \/>\nfor i in range(50, 60):<br \/>\n    if (i &#8211; 50) % 2 == 0:<br \/>\n        X_test[0, i, 0] += 0.5<br \/>\n    else:<br \/>\n        X_test[0, i, 0] -= 0.5<br \/>\n<strong># \u7570\u5e38\u30c7\u30fc\u30bf\u3092\u57fa\u306b\u30e2\u30c7\u30eb\u3067\u518d\u69cb\u7bc9<\/strong><br \/>\nX_test_reconstructed = autoencoder.predict(X_test)\n<\/p>\n<p>&nbsp;<\/p>\n<h3>\u7570\u5e38\u30c7\u30fc\u30bf\u306e\u518d\u69cb\u7bc9\u7d50\u679c\u306e\u78ba\u8a8d<\/h3>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong># x\u8ef8\u306e\u30c7\u30fc\u30bf<\/strong><br \/>\nx = np.arange(1, 101)<br \/>\n<strong># y\u8ef8\u306e\u30c7\u30fc\u30bf\u30922\u3064\u7528\u610f<\/strong><br \/>\ny1 = X_test[0]<br \/>\ny2 = X_test_reconstructed[0]<br \/>\n<strong># \u30d7\u30ed\u30c3\u30c8\u306e\u4f5c\u6210<\/strong><br \/>\nplt.figure(figsize=(10, 5))<br \/>\n<strong># 1\u3064\u76ee\u306e\u30d7\u30ed\u30c3\u30c8<\/strong><br \/>\nplt.plot(x, y1, label=&#8217;test&#8217;, color=&#8217;b&#8217;)<br \/>\n<strong># 2\u3064\u76ee\u306e\u30d7\u30ed\u30c3\u30c8<\/strong><br \/>\nplt.plot(x, y2, label=&#8217;reconstructed&#8217;, color=&#8217;r&#8217;)<br \/>\n<strong># \u30e9\u30d9\u30eb\u306e\u8a2d\u5b9a<\/strong><br \/>\nplt.xlabel(&#8216;timesteps&#8217;)<br \/>\nplt.ylabel(&#8216;value&#8217;)<br \/>\n<strong># \u51e1\u4f8b\u306e\u8868\u793a<\/strong><br \/>\nplt.legend()<br \/>\n<strong># \u30b0\u30e9\u30d5\u306e\u8868\u793a<\/strong><br \/>\nplt.show()<\/p>\n<p><center><img decoding=\"async\" src=\"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-content\/uploads\/sites\/19\/unusual_check.png\" \/><\/p>\n<p>\u9752\u3044\u6ce2\u304c\u7570\u5e38\u30c7\u30fc\u30bf\uff08timesteps=50\u304b\u308959\u306e\u7bc4\u56f2\u306b\u7570\u5e38\u767a\u751f\uff09\u3001\u8d64\u3044\u6ce2\u304c\u305d\u308c\u3092\u57fa\u306b\u518d\u69cb\u7bc9\u3057\u305f\u30c7\u30fc\u30bf\u3067\u3059\u3002<br \/>\u7570\u5e38\u304c\u767a\u751f\u3057\u3066\u3044\u308b\u7bc4\u56f2\u306b\u304a\u3044\u3066\u3001\u30e2\u30c7\u30eb\u304c\u7570\u5e38\u306a\u632f\u308b\u821e\u3044\u306b\u53cd\u5fdc\u3067\u304d\u305a\u3001<br \/>\u5165\u529b\u30c7\u30fc\u30bf\u3068\u518d\u69cb\u7bc9\u30c7\u30fc\u30bf\u306e\u9593\u3067\u8aa4\u5dee\u304c\u767a\u751f\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<p><\/center><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>7. \u7570\u5e38\u691c\u77e5\u306e\u5b9f\u88c5<\/h2>\n<h3>\u7570\u5e38\u5224\u5b9a\u3059\u308b\u95be\u5024\u3092\u5b66\u7fd2\u30c7\u30fc\u30bf\u304b\u3089\u8a2d\u5b9a<\/h3>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong>#\u5404\u5b66\u7fd2\u30c7\u30fc\u30bf\u3068\u5404\u518d\u69cb\u7bc9\u30c7\u30fc\u30bf\u306e\u5e73\u5747\u4e8c\u4e57\u8aa4\u5dee\u3092\u8a08\u7b97\u3057\u3001\u30ea\u30b9\u30c8\u306b\u683c\u7d0d\u3057\u3066\u3044\u304f<\/strong><br \/>\nanom_train = list()<br \/>\nfor i in range(X_train.shape[0]):<br \/>\n    anom = np.sum(np.mean((X_train_reconstructed[i]-X_train[i])**2, axis=0))<br \/>\n    anom_train.append(anom)<br \/>\nanom_train = np.array(anom_train)<br \/>\n<strong>#\u30ea\u30b9\u30c8\u5185\u306e99.9percentile\u3092\u3001\u7570\u5e38\u5224\u5b9a\u306b\u4f7f\u7528\u3059\u308b\u95be\u5024\u306b\u8a2d\u5b9a<\/strong><br \/>\nth_value = np.percentile(anom_train, q=99.9)<\/p>\n<p>&nbsp;<\/p>\n<h3>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u7570\u5e38\u5ea6\u3092\u8a08\u7b97<\/h3>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong>#\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3068\u518d\u69cb\u7bc9\u30c7\u30fc\u30bf\u306e\u5e73\u5747\u4e8c\u4e57\u8aa4\u5dee\u3092\u8a08\u7b97<\/strong><br \/>\nanom_test = list()<br \/>\nfor i in range(X_test.shape[1]):<br \/>\n    anom = (X_test_reconstructed[0][i]-X_test[0][i])**2<br \/>\n    anom_test.append(anom)<br \/>\nanom_test = np.array(anom_test)<\/p>\n<p>&nbsp;<\/p>\n<h3>\u95be\u5024\u3092\u8d85\u904e\u3057\u305f\u304b\u78ba\u8a8d<\/h3>\n<p style=\"border:1px solid #666; padding:2.5rem;\">\n<strong># x\u8ef8\u306e\u30c7\u30fc\u30bf<\/strong><br \/>\nx = np.arange(1, 101)<br \/>\n<strong># y\u8ef8\u306e\u30c7\u30fc\u30bf\u30922\u3064\u7528\u610f<\/strong><br \/>\ny1 = np.full(100, th_value)<br \/>\ny2 = anom_test<br \/>\n<strong># \u30d7\u30ed\u30c3\u30c8\u306e\u4f5c\u6210<\/strong><br \/>\nplt.figure(figsize=(10, 5))<br \/>\n<strong># 1\u3064\u76ee\u306e\u30d7\u30ed\u30c3\u30c8<\/strong><br \/>\nplt.plot(x, y1, label=&#8217;th_value&#8217;, color=&#8217;b&#8217;)<br \/>\n<strong># 2\u3064\u76ee\u306e\u30d7\u30ed\u30c3\u30c8<\/strong><br \/>\nplt.plot(x, y2, label=&#8217;anom_test&#8217;, color=&#8217;r&#8217;)<br \/>\n<strong># \u30e9\u30d9\u30eb\u306e\u8a2d\u5b9a<\/strong><br \/>\nplt.xlabel(&#8216;timesteps&#8217;)<br \/>\nplt.ylabel(&#8216;value&#8217;)<br \/>\n<strong># \u51e1\u4f8b\u306e\u8868\u793a<\/strong><br \/>\nplt.legend()<br \/>\n<strong># \u30b0\u30e9\u30d5\u306e\u8868\u793a<\/strong><br \/>\nplt.show()<\/p>\n<p><center><img decoding=\"async\" src=\"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-content\/uploads\/sites\/19\/unusual_apper.png\" \/><\/p>\n<p>\u9752\u3044\u7dda\u304c\u8a2d\u5b9a\u3057\u305f\u95be\u5024\u3001\u8d64\u3044\u6ce2\u304c\u7570\u5e38\u5ea6\uff08\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3068\u518d\u69cb\u7bc9\u30c7\u30fc\u30bf\u306e\u5e73\u5747\u4e8c\u4e57\u8aa4\u5dee\uff09\u3067\u3059\u3002\u7570\u5e38\u304c\u767a\u751f\u3057\u3066\u3044\u308b\u7bc4\u56f2\u306b\u304a\u3044\u3066\u3001\u7570\u5e38\u5ea6\u304c\u95be\u5024\u3092\u8d85\u904e\u3057\u3066\u3044\u307e\u3059\u3002\u6b63\u3057\u304f\u7570\u5e38\u3092\u691c\u77e5\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<p><\/center>\n<\/div>\n<\/section>\n<style>\n.page h1.entry-title:before {\n    content: 'Column';\n}\n.post h3 {\nborder-bottom:1px solid #26a55b;\nborder-left:2px solid #26a55b;\n}\n.post h4 {\n    margin-left: 3px;\nbackground:#26a55b;\ncolor:#fff;\nborder-left: solid 3px #26a55b;\nborder-bottom: solid 1px #26a55b;\nfont-weight: 500;\npadding: 10px;\nmargin-bottom: 10px;\nmargin-top: 0;\n}\nstrong {\nmargin-top:30px;\n}\n<\/style>\n","protected":false},"excerpt":{"rendered":"<p>\u6771\u4eac\u30b7\u30b9\u30c6\u30e0\u30cf\u30a6\u30b9\u3067\u306f\u3001\u7814\u7a76\u958b\u767a\u30b5\u30dd\u30fc\u30c8\u3060\u3051\u3067\u306f\u306a\u304f\u81ea\u793e\u5185\u3067\u306e\u7814\u7a76\u958b\u767a\u3082\u9032\u3081\u3066\u304a\u308a\u307e\u3059\u3002\u6697\u53f7\u30b3\u30e9\u30e0\u306f\u3001\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306b\u95a2\u308f\u308b\u8a71\u3092\u307e\u3068\u3081\u3066\u304a\u308a\u307e\u3059\u3002R\uff06D\u30d6\u30ed\u30b0\u3067\u306f\u3001\u7814\u7a76\u958b\u767a\u306b\u643a\u308f\u308b\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u751f\u306e\u58f0\u3092\u304a\u5c4a\u3051\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":8,"featured_media":0,"parent":549,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1472","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/pages\/1472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/comments?post=1472"}],"version-history":[{"count":31,"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/pages\/1472\/revisions"}],"predecessor-version":[{"id":1523,"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/pages\/1472\/revisions\/1523"}],"up":[{"embeddable":true,"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/pages\/549"}],"wp:attachment":[{"href":"https:\/\/www.tsh-world.co.jp\/adv-rd\/wp-json\/wp\/v2\/media?parent=1472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}