-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathsample_program_6_8_2.py
More file actions
75 lines (65 loc) · 4.2 KB
/
Copy pathsample_program_6_8_2.py
File metadata and controls
75 lines (65 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
@author: hkaneko
"""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
number_of_bins = 50 # ヒストグラムのビンの数
# 下の y_name を、'boiling_point', 'logS', 'melting_point', 'pIC50', 'pIC50_class', 'pIGC50', 'pIGC50_class' のいずれかにしてください。
# descriptors_with_[y_name].csv というファイルを dataset として読み込み計算します。
# さらに、y_name を別の名前に変えて、ご自身で別途 sample_program_6_8_0_csv.py もしくは
# sample_program_6_8_0_sdf.py で descriptors_with_[y_name].csv というファイルを、
# 他のファイルと同様の形式で準備すれば、同じように計算することができます。
y_name = 'boiling_point'
# 'boiling_point' : 沸点のデータセットの場合
# 'logS' : 水溶解度のデータセットの場合
# 'melting_point' : 融点のデータセットの場合
# 'pIC50' : 薬理活性のデータセットの場合
# 'pIC50_class' : クラス分類用の薬理活性のデータセットの場合
# 'pIGC50' : 環境毒性のデータセットの場合
# 'pIGC50_class' : クラス分類用の環境毒性のデータセットの場合
dataset = pd.read_csv('descriptors_with_{0}.csv'.format(y_name), index_col=0) # 物性・活性と記述子のデータセットの読み込み
dataset = dataset.replace(np.inf, np.nan).fillna(np.nan) # inf を NaN に置き換え
dataset = dataset.drop(dataset.columns[dataset.isnull().any()], axis=1) # NaN を含む変数を削除
if dataset.iloc[:, 0].dtype == 'float': # 回帰分析
dataset = dataset.drop(dataset.columns[dataset.std() == 0], axis=1) # 標準偏差が 0 の特徴量 (記述子) を削除
# y のヒストグラム
plt.rcParams['font.size'] = 18 # 横軸や縦軸の名前の文字などのフォントのサイズ
plt.hist(dataset.iloc[:, 0], bins=number_of_bins) # ヒストグラムの作成
plt.xlabel(dataset.columns[0]) # 横軸の名前
plt.ylabel('frequency') # 縦軸の名前
plt.show() # 以上の設定において、グラフを描画
# 相関行列
correlation_coefficients = dataset.corr() # 相関行列の計算
correlation_coefficients.to_csv('correlation_coefficients_{0}.csv'.format(y_name)) # 相関行列を csv ファイルとして保存
# 相関行列のヒートマップ (相関係数の値なし)
plt.rcParams['font.size'] = 12
sns.heatmap(correlation_coefficients, vmax=1, vmin=-1, cmap='seismic', square=True, annot=False)
plt.xlim([0, correlation_coefficients.shape[0]])
plt.ylim([0, correlation_coefficients.shape[0]])
plt.show()
# y との相関係数のヒストグラム
plt.rcParams['font.size'] = 18 # 横軸や縦軸の名前の文字などのフォントのサイズ
plt.hist(correlation_coefficients.iloc[1:, 0], bins=number_of_bins) # ヒストグラムの作成
plt.xlabel('correlation coef. with {0}'.format(dataset.columns[0])) # 横軸の名前
plt.ylabel('frequency') # 縦軸の名前
plt.show() # 以上の設定において、グラフを描画
# y と最も相関係数の絶対値の高い記述子と y の散布図
correlation_wity_y_max_descriptor = abs(correlation_coefficients.iloc[1:, 0]).idxmax()
plt.rcParams['font.size'] = 18 # 横軸や縦軸の名前の文字などのフォントのサイズ
plt.scatter(dataset[correlation_wity_y_max_descriptor], dataset.iloc[:, 0], c='blue')
plt.xlabel(correlation_wity_y_max_descriptor)
plt.ylabel(dataset.columns[0])
plt.show()
else:
x = dataset.iloc[:, 1:]
x = x.drop(x.columns[x.std() == 0], axis=1) # 標準偏差が 0 の特徴量 (記述子) を削除
# 相関行列
correlation_coefficients = x.corr() # 相関行列の計算
correlation_coefficients.to_csv('correlation_coefficients_{0}.csv'.format(y_name)) # 相関行列を csv ファイルとして保存
# 相関行列のヒートマップ (相関係数の値なし)
plt.rcParams['font.size'] = 12
sns.heatmap(correlation_coefficients, vmax=1, vmin=-1, cmap='seismic', square=True, annot=False)
plt.show()