-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathML_Prac.py
58 lines (45 loc) · 1.56 KB
/
ML_Prac.py
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
import pandas as pd
#顯示所有列
pd.set_option('display.max_columns', None)
#顯示所有行
pd.set_option('display.max_rows', None)
#設置value的顯示長度為100,預設為50
pd.set_option('max_colwidth',100)
def corr_matrix(df, size=6, method="pearson"):
from matplotlib import pyplot as plt
import numpy as np
correlations = df.corr(method)
# plot correlation matrix
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(correlations, vmin=-1, vmax=1)
fig.colorbar(cax)
ticks = np.arange(0, size, 1)
# ax.set_xticks(ticks)
# ax.set_yticks(ticks)
# ax.set_xticklabels(labels)
# ax.set_yticklabels(labels)
plt.xticks(range(len(correlations.columns)), correlations.columns)
plt.yticks(range(len(correlations.columns)), correlations.columns)
plt.show()
def scatter_matrix(df):
from matplotlib import pyplot as plt
from pandas.plotting import scatter_matrix
scatter_matrix(df)
plt.show()
#========================================================================#
# 讀入 csv 文字檔
csv_file = "ML_Data_1563783994"
vib_df = pd.read_csv(csv_file + '.csv', encoding='utf-8')
# print(type(vib_df))
vib_df.head()
# print(vib_df.iloc[1][4])
vib_df_T = vib_df.T
# vib_df_T.to_csv(csv_file + '_output.csv', index=False, encoding='big5')
# scatter_matrix(vib_df) #plot scatter form of correlation matrix
corr_matrix(vib_df_T, 12, "kendall") #plot correlation matrix
#kendall
#spearman
#For output corr result
# corr_df = vib_df.corr()
# corr_df.to_csv('output.csv', index=False, encoding='big5')