Browse Source

完成了二维表格散点图

完成了矩阵二维表格散点图
Huan 5 years ago
parent
commit
2d62349a7e

BIN
DSGC/__pycache__/Algebra_Systemctl.cpython-37.pyc


+ 1 - 1
Data_Science/Learn.py

@@ -240,7 +240,7 @@ class Form:
 
     def T(self, name, new=True):
         get = self.get_Sheet(name)
-        re = get.T
+        re = get.T.copy()#复制一份,防止冲突
         if new:
             self.Add_Form(re,f'{name}.T')
         return re

BIN
Data_Science/__pycache__/Learn.cpython-37.pyc


BIN
Data_Science/__pycache__/Me_learn.cpython-37.pyc


BIN
Data_Science/__pycache__/__init__.cpython-37.pyc


+ 88 - 0
Learn_Numpy.py

@@ -917,6 +917,67 @@ class Learner:
         tab.render(Dic)
         return Dic
 
+    def Merge(self,name,axis=0):#aiis:0-横向合并(hstack),1-纵向合并(vstack),2-深度合并
+        sheet_list = []
+        for i in name:
+            sheet_list.append(self.get_Sheet(i))
+        get = {0:np.hstack,1:np.vstack,2:np.dstack}[axis](sheet_list)
+        self.Add_Form(np.array(get),f'{name[0]}合成')
+
+    def Split(self,name,split=2,axis=0):#aiis:0-横向分割(hsplit),1-纵向分割(vsplit)
+        sheet = self.get_Sheet(name)
+        get = {0:np.hsplit,1:np.vsplit,2:np.dsplit}[axis](sheet,split)
+        for i in get:
+            self.Add_Form(i,f'{name[0]}分割')
+
+    def Two_Split(self,name,split,axis):#二分切割(0-横向,1-纵向)
+        sheet = self.get_Sheet(name)
+        try:
+            split = float(eval(split))
+            if split < 1:
+                split = int(split * len(sheet) if axis == 1 else len(sheet[0]))
+            else:
+                raise Exception
+        except:
+            split = int(split)
+        if axis == 0:
+            self.Add_Form(sheet[:,split:], f'{name[0]}分割')
+            self.Add_Form(sheet[:,:split], f'{name[0]}分割')
+
+    def Deep(self,sheet:np.ndarray):
+        return sheet.ravel()
+
+    def Down_Ndim(self,sheet:np.ndarray):#横向
+        down_list = []
+        for i in sheet:
+            down_list.append(i.ravel())
+        return np.array(down_list)
+
+    def LongitudinalDown_Ndim(self,sheet:np.ndarray):#纵向
+        down_list = []
+        for i in range(len(sheet[0])):
+            down_list.append(sheet[:,i].ravel())
+        return np.array(down_list).T
+
+    def Reval(self,name,axis):#axis:0-横向,1-纵向(带.T),2-深度
+        sheet = self.get_Sheet(name)
+        self.Add_Form({0:self.Down_Ndim,1:self.LongitudinalDown_Ndim,2:self.Deep}[axis](sheet).copy(),f'{name}伸展')
+
+    def Del_Ndim(self,name):#删除无用维度
+        sheet = self.get_Sheet(name)
+        self.Add_Form(np.squeeze(sheet), f'{name}降维')
+
+    def T(self,name,Func:list):
+        sheet = self.get_Sheet(name)
+        if sheet.ndim <= 2:
+            self.Add_Form(sheet.T.copy(), f'{name}.T')
+        else:
+            self.Add_Form(np.transpose(sheet,Func).copy(), f'{name}.T')
+
+    def reShape(self,name,shape:list):
+        sheet = self.get_Sheet(name)
+        self.Add_Form(sheet.reshape(shape).copy(), f'{name}.r')
+
 class Study_MachineBase:
     def __init__(self,*args,**kwargs):
         self.Model = None
@@ -1051,6 +1112,32 @@ class View_data(To_PyeBase):#绘制预测型热力图
     def Des(self,Dic,*args,**kwargs):
         return Dic,
 
+class MatrixScatter(To_PyeBase):
+    def Des(self, Dic, *args, **kwargs):
+        tab = Tab()
+
+        data = self.x_trainData
+        print(data.ndim)
+        if data.ndim <= 2:#维度为2
+            c = (Scatter()
+                 .add_xaxis([f'{i}' for i in range(data.shape[1])])
+                 .set_global_opts(title_opts=opts.TitleOpts(title=f'矩阵散点图'), **global_Leg)
+                 )
+            if data.ndim == 2:
+                for num in range(len(data)):
+                    i = data[num]
+                    c.add_yaxis(f'{num}',[[f'{num}',x] for x in i],color='#FFFFFF')
+            else:
+                c.add_yaxis(f'0', [[0,x]for x in data],color='#FFFFFF')
+            c.set_series_opts(label_opts=opts.LabelOpts(is_show=True,color='#000000',position='inside',
+            formatter=JsCode("function(params){return params.data[2];}"),
+            ))
+            tab.add(c,'矩阵散点图')
+
+        save = Dic + r'/render.HTML'
+        tab.render(save)  # 生成HTML
+        return save,
+
 class Cluster_Tree(To_PyeBase):
     def Des(self, Dic, *args, **kwargs):
         tab = Tab()
@@ -2854,6 +2941,7 @@ class Machine_Learner(Learner):#数据处理者
                           'HeatMap':Numpy_To_HeatMap,
                           'FeatureY-X':Feature_scatter_YX,
                           'ClusterTree':Cluster_Tree,
+                          'MatrixScatter':MatrixScatter,
                           }
         self.Learner_Type = {}#记录机器的类型
 

+ 124 - 5
Machine_learning.py

@@ -9,9 +9,10 @@ import Learn_Numpy
 import webbrowser
 
 def Main():
-    global top,ML,Form_List,PATH,bg,bbg,fg
+    global top,ML,Form_List,PATH,bg,bbg,fg,Merge_list
     PATH = os.getcwd()
     Form_List = []
+    Merge_list = []
     ML = Learn_Numpy.Machine_Learner()
 
     top = tkinter.Tk()
@@ -86,7 +87,56 @@ def Main():
     a_y += 1
     Form_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 10)  # 显示符号
     Form_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=10, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
+    #422
+    a_y += 10
+    tkinter.Button(top, bg=bbg, fg=fg, text='添加数据', command=Merge_Add, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
+    tkinter.Button(top, bg=bbg, fg=fg, text='删除数据', command=Merge_Del, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x + 1, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
+    tkinter.Button(top, bg=bbg, fg=fg, text='组合数据', command=Merge, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x + 2, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
+
+    global Processing_type, Shape_Input, Merge_BOX
+    a_y += 1
+    Merge_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3)  # 显示符号
+    Merge_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
+
+    a_y += 3
+    Processing_type = tkinter.IntVar()#正,负,0
+    lable = ['横向处理','纵向处理','深度处理']#复选框
+    for i in range(3):
+        tkinter.Radiobutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg,text=lable[i],
+                            variable=Processing_type, value=i).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
+
+    a_y += 1
+    tkinter.Button(top, bg=bbg, fg=fg, text='数据切片', command=Two_Split, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
+    tkinter.Button(top, bg=bbg, fg=fg, text='数据分割', command=Split, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x + 1, row=a_y,columnspan=2,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
 
+    a_y += 1
+    tkinter.Label(top, text='重塑形状:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
+    Shape_Input = tkinter.Entry(top, width=width_B)
+    Shape_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
+    tkinter.Button(top, bg=bbg, fg=fg, text='矩阵重塑', command=Reshape, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x + 2, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
+
+    a_y += 1
+    tkinter.Button(top, bg=bbg, fg=fg, text='矩阵伸展', command=Reval, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
+    tkinter.Button(top, bg=bbg, fg=fg, text='矩阵降维', command=Del_Ndim, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x + 1, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
+    tkinter.Button(top, bg=bbg, fg=fg, text='矩阵转置', command=T, font=FONT, width=width_B,
+                   height=height_B).grid(column=a_x + 2, row=a_y,
+                                         sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
 
     a_x += 3
     tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y)  # 设置说明
@@ -104,7 +154,7 @@ def Main():
     Put = tkinter.Entry(top, width=width_B * 2, textvariable=X_OUT)
     Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
     Put['state'] = 'readonly'
-    tkinter.Button(top, bg=bbg, fg=fg, text='选用特征集', command=set_Feature, font=FONT, width=width_B,
+    tkinter.Button(top, bg=bbg, fg=fg, text='选用X集', command=set_Feature, font=FONT, width=width_B,
                    height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
 
     Y_OUT = tkinter.StringVar()
@@ -112,7 +162,7 @@ def Main():
     Put = tkinter.Entry(top, width=width_B * 2, textvariable=Y_OUT)
     Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
     Put['state'] = 'readonly'
-    tkinter.Button(top, bg=bbg, fg=fg, text='选用标签集', command=set_Label, font=FONT, width=width_B,
+    tkinter.Button(top, bg=bbg, fg=fg, text='选用Y集', command=set_Label, font=FONT, width=width_B,
                    height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
 
     ML_OUT = tkinter.StringVar()
@@ -345,7 +395,7 @@ def Main():
     tkinter.Button(top, bg=bbg, fg=fg, text='获取数据', command=Add_View_data, font=FONT, width=width_B,
                    height=height_B).grid(column=a_x+1, row=a_y,
                                          sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
-    tkinter.Button(top, bg=bbg, fg=fg, text='数据y-x散点图',command=Add_FeatureY_X, font=FONT, width=width_B, height=height_B).grid(
+    tkinter.Button(top, bg=bbg, fg=fg, text='矩阵散点图',command=Add_MatrixScatter, font=FONT, width=width_B, height=height_B).grid(
         column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
 
     a_x += 3
@@ -366,6 +416,73 @@ def Main():
 
     top.mainloop()
 
+#90
+
+def Reshape():
+    global ML,Processing_type
+    shape = eval(f'[{Shape_Input.get()}]')[0]
+    ML.reShape(get_Name(),shape)
+    Update_BOX()
+
+def T():
+    global ML,Processing_type,Shape_Input
+    try:
+        Func = eval(f'[{Shape_Input.get()}]')
+    except:
+        Func = None
+    ML.T(get_Name(),Func)
+    Update_BOX()
+
+def Del_Ndim():
+    global ML
+    ML.Del_Ndim(get_Name())
+    Update_BOX()
+
+def Reval():
+    global ML,Processing_type
+    Type = Processing_type.get()
+    ML.Reval(get_Name(),Type)
+    Update_BOX()
+
+def Two_Split():
+    global ML,Processing_type,Shape_Input
+    Type = Processing_type.get()
+    ML.Two_Split(get_Name(),Shape_Input.get(),Type)
+    Update_BOX()
+
+def Split():
+    global ML,Processing_type,Shape_Input
+    Type = Processing_type.get()
+    try:
+        Split = eval(f'[{Shape_Input.get()}]')[0]
+    except:
+        Split = 2
+    ML.Split(get_Name(),Split,Type)
+    Update_BOX()
+
+def Merge():
+    global Merge_list,ML,Processing_type
+    if len(Merge_list) < 1:
+        return False
+    Type = Processing_type.get()
+    ML.Merge(Merge_list,Type)
+    Update_BOX()
+
+def Update_Merge():
+    global Merge_list,Merge_BOX
+    Merge_BOX.delete(0, tkinter.END)
+    Merge_BOX.insert(tkinter.END, *Merge_list)
+
+def Merge_Del():
+    global Merge_list,Merge_BOX
+    del Merge_list[Merge_BOX.curselection()[0]]
+    Update_Merge()
+
+def Merge_Add():
+    global Merge_list
+    name = get_Name()
+    Merge_list.append(name)
+    Update_Merge()
 
 def Del_Leaner():
     Learn = get_Learner(True)
@@ -415,7 +532,6 @@ def Fit_Learner():
     tkinter.messagebox.showinfo('训练完成', f'针对训练数据({(1 - split) * 100}%)评分结果为:{socore[0]}\n'
                                         f'针对测试数据评分({split * 100}%)结果为:{socore[1]}')
 
-
 def set_Feature():
     global X_OUT
     X_OUT.set(get_Name())
@@ -448,6 +564,9 @@ def get_Learner(Type=False):
         except:
             return None
 
+def Add_MatrixScatter():  # 添加Lenear的核心
+    Add_leaner('MatrixScatter')
+
 def Add_View_data():  # 添加Lenear的核心
     ML.Add_View_data(get_Learner(), Text=get_Args_Learner())
     Update_Leaner()

BIN
__pycache__/Learn.cpython-37.pyc


BIN
__pycache__/Learn_Numpy.cpython-37.pyc