Полная ошибка: -
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Kapil Sharma\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Kapil Sharma\Desktop\RexD ML Tool\KRexD.py", line 112, in ok_clicked
imputer.fit(X[:, listOfMissingValuesIndexes])
UnboundLocalError: local variable 'X' referenced before assignment**
Я пытаюсь выполнить этот код: -
def yes_clicked():
#Here we have to do data preprocessing
dataPreprocessingWindow = Toplevel()
dataPreprocessingWindow.title("Data Preprocessing Window")
dataPreprocessingWindow.geometry("700x700")
#Importing the dataset
dataset = pd.read_csv('combined.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
Label(dataPreprocessingWindow,text = "Data Imported",font=50).grid()
missing_values_indexes = StringVar()
icategorical_values_indexes = StringVar()
dcategorical_values_indexes = StringVar()
def ok_clicked():
listOfMissingValuesIndexes = []
listOfICategoricalValuesIndexes = []
listOfDCategoricalValuesIndexes = []
index = missing_values_indexes.get()
iindex = icategorical_values_indexes.get()
dindex = dcategorical_values_indexes.get()
for i in index:
if(i==' '):
pass
else:
ind = int(i)
listOfMissingValuesIndexes.append(ind)
for i in iindex:
if(i==' '):
pass
else:
ind = int(i)
listOfICategoricalValuesIndexes.append(ind)
for i in dindex:
if(i==' '):
pass
else:
ind = int(i)
listOfDCategoricalValuesIndexes.append(ind)
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
imputer.fit(X[:, listOfMissingValuesIndexes])
X[:, listOfMissingValuesIndexes] = imputer.transform(X[:, listOfMissingValuesIndexes])
print(X)
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), listOfICategoricalValuesIndexes)], remainder='passthrough')
X = np.array(ct.fit_transform(X))
print(X)
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
y = le.fit_transform(y)
print(y)
Label(dataPreprocessingWindow,text = "Enter indexes(space separated) that can contain missing data",font=70).grid(row=0,column=0)
Entry(dataPreprocessingWindow,textvariable = missing_values_indexes,width=50).grid()
Label(dataPreprocessingWindow,text = "Enter indexes(space separated) of independent variables that can contain categorical data",font=70).grid()
Entry(dataPreprocessingWindow,textvariable = icategorical_values_indexes,width=50).grid()
Label(dataPreprocessingWindow,text = "Enter indexes(space separated) of dependent variables that can contain missing data",font=70).grid()
Entry(dataPreprocessingWindow,textvariable = dcategorical_values_indexes,width=50).grid()
Button(dataPreprocessingWindow,text = "OK",command = ok_clicked,cursor="hand2").grid()