# 企業決算情報の可視化 ¶

このチュートリアルでは、企業の決算情報を可視化します。

## 必要なモジュール ¶

In [1]:

import numpy as np

import pandas as pd

from renom_tda.topology import Topology
from renom_tda.lens import TSNE


## データのインポート ¶

In [2]:

pdata = pd.read_csv("finance.csv")


## テキストデータと数値データの抽出 ¶

In [3]:

text_data = np.array(pdata.loc[:, pdata.dtypes == "object"])
text_data_columns = pdata.columns[:4]

number_data = np.array(pdata.loc[:, np.logical_or(pdata.dtypes == "float", pdata.dtypes == "int")])
number_data_columns = pdata.columns[4:]


## トポロジーのインスタンス作成 ¶

In [4]:

topology = Topology()


## データのロード ¶

In [5]:

topology.load_data(number_data, number_data_columns=number_data_columns, text_data=text_data, text_data_columns=text_data_columns, standardize=True)


## ポイントクラウド作成 ¶

In [6]:

metric = None
lens = [TSNE(components=[0,1])]
topology.fit_transform(metric=metric, lens=lens)

projected by TSNE.


## 位相空間へマッピング ¶

In [7]:

topology.map(resolution=50, overlap=0.5, eps=0.2, min_samples=2)

created 963 nodes.
created 3146 edges.


## 色付け & 表示 ¶

In [8]:

e_col = ["sales(million yen)", "operationg profit(million yen)", "ordinaly profit(million yen)",
"current profit(million yen)", "total assets(million yen)", "owned capital(million yen)",
"capital(million yen)", "interest-bearing debt(million yen)", "aggregate market value",
"ratio of worth", "return on equity", "return on assets", "number of stocks issued"]
for i in range(topology.number_data.shape[1]):
print("colored by %s (%s)." % (number_data_columns[i], e_col[i]))

topology.color(topology.number_data[:, i], color_method="mean", color_type="rgb")
topology.show(fig_size=(10, 10), node_size=5, edge_width=1, mode=None, strength=None)

colored by 売上高(百万円) (sales(million yen)).

colored by 営業利益(百万円) (operationg profit(million yen)).

colored by 経常利益(百万円) (ordinaly profit(million yen)).

colored by 当期利益(百万円) (current profit(million yen)).

colored by 総資産(百万円) (total assets(million yen)).

colored by 自己資本(百万円) (owned capital(million yen)).

colored by 資本金(百万円) (capital(million yen)).

colored by 有利子負債(百万円) (interest-bearing debt(million yen)).

colored by 時価総額（百万円） (aggregate market value).

colored by 自己資本比率 (ratio of worth).

colored by ROE (return on equity).

colored by ROA (return on assets).

colored by 発行済株式数 (number of stocks issued).


## 検索 ¶

In [9]:

search_dicts = [{
"data_type": "number",
"operator": ">",
"column": "売上高(百万円)",
"value": 20000
}, {
"data_type": "number",
"operator": ">",
"column": "ROE",
"value": 20
}]

target = topology.number_data[:, 0]
topology.color(target, color_method="mean", color_type="rgb")
node_index = topology.search_from_values(search_dicts=search_dicts, target=None, search_type="column")
topology.show(fig_size=(10,10), node_size=10, edge_width=0.5)

In [10]:

node_index

Out[10]:

[302,
303,
304,
305,
348,
349,
350,
351,
394,
395,
396,
397,
398,
399,
400,
440,
441,
443,
444,
445,
446,
486,
487,
488,
489,
490,
491,
492,
493,
494,
495,
496,
497,
498,
531,
532,
533,
534,
535,
536,
537,
538,
539,
540,
541,
542,
543,
579,
580,
581,
582,
584,
585,
586,
587,
588,
591,
592,
623,
624,
625,
626,
627,
628,
629,
630,
631,
632,
635,
636,
666,
667,
668,
669,
670,
671,
672,
673,
674,
711,
712,
713,
714,
765,
766,
773,
774,
775,
803,
804,
805,
811,
812,
813,
839,
840,
841,
854,
855,
860,
871,
872,
873,
874,
886,
887,
896,
897,
898,
899,
900,
915,
916,
917,
918,
932,
933,
952,
953,
956,
957]


## csvファイルに出力 ¶

トポロジーインスタンスはノードIDから、ノード内に含むデータをcsvファイルに出力することができます。
In [11]:

topology.output_csv_from_node_ids("output.csv", node_ids=node_index, skip_header=False)