解析結果をエクセルに出力しようとした所下記エラーが出てしまいます。
ValueError("Cannot convert {0!r} to Excel".format(value))
また作成したtkinterをexe化しようとした所下記エラーが出てしまいます。
for field, value in iter_fields(node):
RecursionError: maximum recursion depth exceeded
どなたか解決方法ご存知でしたら教えて頂きたいです。
python
1 2 3import sys 4import tkinter as tk 5import tkinter.filedialog as tkfile 6import datetime as dt 7import time 8import threading 9from tkinter import filedialog 10from tkinter import ttk 11from datetime import datetime 12from tkinter import messagebox 13import pandas as pd 14from sklearn.model_selection import train_test_split 15import os, tkinter, tkinter.filedialog, tkinter.messagebox 16from openpyxl import Workbook 17 18 19class Application(tk.Frame): 20 def __init__(self, master): 21 super().__init__(master) 22 23 self.master = master 24 self.master.title('ana_ver2') 25 self.master.geometry("500x750") 26 self.master.configure(bg='azure') 27 self.create_widgets() 28 29#--------------------widjet----------------------------------------------------------------------- 30 def create_widgets(self): 31 varS = tkinter.StringVar() 32 varT1 = tkinter.BooleanVar() 33 varT2 = tkinter.BooleanVar() 34 #------csv read-------------------------------------------------------------- 35 self.input_box = tkinter.Entry(width=40,fg='grey') #csvログインプット 36 self.input_box.place(x=10, y=50) 37 38 self.input_label = tkinter.Label(text="----csv read----",fg='grey',bg='snow') 39 self.input_label.place(x=10, y=20) 40 41 self.button = tkinter.Button(text="read",bg="gainsboro",command=file_select) 42 self.button.place(x=400, y=52) 43 44 #------select X, y--------------------------------------------------------------------- 45 self.input_label = tkinter.Label(text="----select X , y----",fg='grey',bg='snow') 46 self.input_label.place(x=10, y=80) 47 48 self.input_label = tkinter.Label(text="...columns list...",fg='grey') 49 self.input_label.place(x=10, y=170) 50 51 self.input_box2 = tkinter.Entry(width=40) 52 self.input_box2.place(x=10, y=110) 53 54 self.listbox = tk.Listbox(selectmode="multiple") 55 self.listbox.configure(width=30,height=10) 56 self.listbox.place(x=10, y=200) 57 58 self.input_label = tkinter.Label(text="data_shape",fg='grey') 59 self.input_label.place(x=310, y=202) 60 61 self.input_boxS = tkinter.Entry(width=9) 62 self.input_boxS.place(x=400, y=200) 63 64 65 self.btn3 = tk.Button(text='X_select',bg="lavender",command = lambda : btn_click3(self.input_box.get())) 66 self.btn3.place(x=400,y=108) 67 68 self.input_box3 = tkinter.Entry(width=40) 69 self.input_box3.place(x=10, y=140) 70 71 self.btn4 = tk.Button(text='y_select',bg="lavender",command = lambda : btn_click4(self.input_box.get())) 72 self.btn4.place(x=400,y=145) 73 74 scrollbar = ttk.Scrollbar(command=self.listbox.yview) 75 self.listbox['yscrollcommand'] = scrollbar.set 76 scrollbar.place(x=290,y=200) 77 78 79 #------- time ---------------------------------------------------------------------------------------------------------------- 80 81 82 self.label4 = tk.Label(text=datetime.now().strftime("%Y/%m/%d %H:%M:%S"),fg="black",font=("meiryo",15)) 83 self.label4.place(x=20,y=690) 84 #self.master.after(100,create_widgets) 85 86 #--------ana ---------------------------------------------------------------------------------------------------------------------------- 87 88 self.btn5 = tk.Button(text='----ana-----',width=15,bg='ivory2',command = lambda : ana_do(self.input_box.get(),self.input_box2.get(),self.input_box3.get())) 89 self.btn5.place(x=310,y=340) 90 91 92 self.input_label = tkinter.Label(text="----Multiple regression analysis----",bg='Navajo White3') 93 self.input_label.place(x=10, y=400) 94 95 96 self.input_label = tkinter.Label(text="influence coefficient") 97 self.input_label.place(x=10, y=440) 98 99 self.input_coef = tkinter.Entry(width=40) 100 self.input_coef.place(x=10, y=460) 101 102 self.input_label = tkinter.Label(text="coefficient of determination") 103 self.input_label.place(x=10, y=490) 104 105 self.input_score = tkinter.Entry(width=10) 106 self.input_score.place(x=10, y=510) 107 108 self.input_label = tkinter.Label(text="----Logistic regression----",bg='Navajo White3') 109 self.input_label.place(x=10, y=550) 110 111 self.input_label = tkinter.Label(text="misclassifiend number") 112 self.input_label.place(x=10, y=590) 113 114 self.input_NG = tkinter.Entry(width=10) 115 self.input_NG.place(x=10, y=610) 116 117 self.input_label = tkinter.Label(text="correct answer rate") 118 self.input_label.place(x=10, y=640) 119 120 self.input_G = tkinter.Entry(width=10) 121 self.input_G.place(x=10, y=660) 122 123#---------------------------------------------------------------------------------------------------------- 124 125 126#------csv botton1 push------------------------------------------------------------------------ 127def file_select(): 128 129 idir = 'C:\python_test' #初期フォルダ 130 filetype = [("","*")] #拡張子の選択 131 file_path = tkinter.filedialog.askopenfilename(filetypes = filetype, initialdir = idir) 132 app.input_box.insert(tkinter.END, file_path) #結果を表示 133 134 df_a = pd.read_csv(file_path) 135 #カラムlistbox表示 136 col_name=df_a.columns.values 137 138 for item in col_name: 139 app.listbox.insert(tkinter.END, item) 140#------select botton3 , 4 push------------------------------------------------------------------------------------ 141 142def btn_click3(FP): 143 df_a = pd.read_csv(FP) 144 col_name=df_a.columns.values 145 146 shape_ = df_a.shape 147 shape_ = " ".join(map(str, shape_)) 148 shape_ =shape_.replace(" "," , ") 149 150 app.input_boxS.insert(tkinter.END, shape_) 151 152 if len(app.listbox.curselection()) == 0: 153 return 154 index = list(app.listbox.curselection())#タプルをかえす 155 156 app.input_box2.insert(tkinter.END, col_name[index]) 157 #テキストbox clear 158 app.listbox.select_clear(0,tk.END) 159 160def btn_click4(FP): 161 df_a = pd.read_csv(FP) 162 col_name=df_a.columns.values 163 164 if len(app.listbox.curselection()) == 0: 165 return 166 index = list(app.listbox.curselection())#タプルをかえす 167 168 app.input_box3.insert(tkinter.END, col_name[index]) 169 #テキストbox clear 170 app.listbox.select_clear(0,tk.END) 171 172#---ana botton5 push -------------------------------------------------------------- 173 174def ana_do(FP,X,y): 175 messagebox.showinfo("ana_do", "解析処理を実行します") 176 df_a = pd.read_csv(FP) 177 col_name=df_a.columns 178 179 #カラム名数処理繰り返し 180 for i in range(len(col_name)): 181 182 #カラムobjectの時の処理 要素抽出→置き換え 183 if df_a[col_name[i]].dtypes==object: 184 list_a = df_a[col_name[i]].unique() 185 186 for u in range(len(list_a)): 187 df_a[col_name[i]] = df_a[col_name[i]].replace(list_a[u], str(u)) 188 189 #カラム毎にfloat変換 190 df_a[col_name[i]] =df_a[col_name[i]].astype(float) 191 192 #Entryからの返り値をリスト化 193 X_list = X.replace("[","") 194 X_list = X_list.replace("]","") 195 X_list = X_list.replace("'","") 196 X_list = X_list.replace("\n","") 197 X_list = X_list.split(" ") 198 print(X_list) 199 200 y_list = y.replace("[","") 201 y_list = y_list.replace("]","") 202 y_list = y_list.replace("'","") 203 #y_a = df_ay.replace(" ",",") 204 print(y_list) 205 206 X_a=df_a[X_list] 207 #X_a=df_a[["age","job","marital","education","balance","housing","loan","contact","duration","campaign","pdays","previous","poutcome"]] 208 209 y_a=df_a[y_list] 210 211 #学習データとtestデータに分ける 212 from sklearn.model_selection import train_test_split 213 # train_test_splitを使って、データセットをトレーニングデータとテストデータに分割する。 7:3 214 X_train, X_test, y_train, y_test = train_test_split(X_a, y_a, test_size=0.3,random_state=0) 215 216 #線形回帰モデル読み込み 217 from sklearn.linear_model import LinearRegression 218 lr=LinearRegression() 219 220 lr.fit(X_train,y_train) 221 lr.predict(X_test) 222 223 coef_ = lr.coef_ 224 #coef_ = [round(coef_[n], 5) for n in range(len(coef_ ))] 225 226 227 score_ = '{:.3f}'.format(lr.score(X_train,y_train)) 228 229 app.input_coef.insert(tkinter.END, coef_) 230 app.input_score.insert(tkinter.END, score_) 231 232 print(lr.coef_)#重み 233 print(lr.score(X_train,y_train)) #決定係数 0.22全然だめ 234 print(lr.score(X_test,y_test)) #決定係数 235 236 #モデル読み込み 237 from sklearn.linear_model import LogisticRegression 238 Lr=LogisticRegression() 239 240 #モデルに適合 241 Lr.fit(X_train,y_train) 242 #テストデータ予測 243 y_b =Lr.predict(X_test) 244 245 #誤判定件数確認 246 from sklearn.metrics import confusion_matrix 247 #print(confusion_matrix(y_test,y)) 248 249 NG_= (y_b != y_test).sum() 250 app.input_NG.insert(tkinter.END, NG_) 251 252 253 print('ロジスティック回帰 誤分類の個数:', (y_b != y_test).sum()) 254 255 #正答率を確認 256 from sklearn.metrics import accuracy_score 257 258 G_= '{:.3f}'.format(accuracy_score(y_test,y_b)) 259 print('ロジスティック回帰 正答率:' , accuracy_score(y_test,y_b)) 260 app.input_G.insert(tkinter.END, G_) 261 262 wb = Workbook() 263 ws = wb.active 264 ws.title = "ana_" 265 ws['A1']="重回帰分析、ロジスティック回帰" 266 ws['A2']="影響因子" 267 ws['C2']=X_list 268 ws['A3']="影響係数" 269 ws['C3']=lr.coef_ 270 ws['A4']=NG_ 271 272 wb.save('ana_.xlsx') 273 274 275#------------------------------------------------------------------------------ 276 277root = tk.Tk() 278app = Application(master=root) 279app.mainloop() 280
あなたの回答
tips
プレビュー