我正在研究机器学习算法,并在python中开发前端。我正在尝试使用SVR,但我遇到此错误 init ()时遇到了意外的关键字参数'kernel',请帮助我解决此错误。我已经搜索了大量有关此问题的信息,但一无所获。我也可以共享完整的代码。
class PredictSVR(tk.Frame):
def __init__(self, parent, controller):
self.controller = controller
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Predictions", font=TITLE_FONT)
label.place(x=500,y=30,width=592,height=44)
self.regressorlabel = tk.Label(self,text="Regressor Intercept:" ,font=HEADING_FONT)
self.regressorlabel.place(x=60,y=70,width=300,height=44)
self.regressor = tk.Label(self, font=("Times New Roman", 14))
self.regressor.place(x=330,y=70,width=200,height=44)
self.valueslabel = tk.Label(self,text="Actual and Predicted Values:" ,font=HEADING_FONT)
self.valueslabel.place(x=60,y=130,width=400,height=44)
self.values= Text(self)
self.values.place(x=100,y=180,width=200,height=480)
self.visuallabel = tk.Label(self,text="Data Visualization" ,font=HEADING_FONT)
self.visuallabel.place(x=600,y=130,width=400,height=44)
self.mbelabel = tk.Label(self,text="Mean Absolute Error:" ,font=HEADING_FONT)
self.mbelabel.place(x=1070,y=230,width=300,height=44)
self.mbe = Text(self)
self.mbe.place(x=1100,y=270,width=170,height=20)
self.mselabel = tk.Label(self,text="Mean Squared Error:" ,font=HEADING_FONT)
self.mselabel.place(x=1070,y=300,width=300,height=44)
self.mse = Text(self)
self.mse.place(x=1100,y=340,width=170,height=20)
self.rmselabel = tk.Label(self,text="Root Mean Squared Error:" ,font=HEADING_FONT)
self.rmselabel.place(x=1080,y=370,width=350,height=44)
self.rmse = Text(self)
self.rmse.place(x=1100,y=410,width=170,height=20)
button1 = tk.Button(self, text="Back",
command=lambda: controller.show_frame(SVRp2))
button2 = tk.Button(self, text="Home",
command=lambda: controller.show_frame(StartPage))
button1.place(x=1000,y=700,width=200,height=44)
button2.place(x=1250,y=700,width=200,height=44)
def PredictData(self):
text=self.controller.PathVar
dataset = pd.read_csv(text)
X = dataset[['TEMPERATURE', 'HUMIDITY']]
y = dataset['UNIT_SALES']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
y_rbf = svr_rbf.fit(X, y).predict(X)
y_lin = svr_lin.fit(X, y).predict(X)
y_poly = svr_poly.fit(X, y).predict(X)
svr = SVR(kernel='linear')
svr.fit(X_train,y_train)
pred_SVR = svr.predict(X_test)
df = pd.DataFrame({'Actual': y_test.values, 'Predicted': pred_SVR})
self.values.insert(INSERT, df)
colName=list(dataset.columns.values)
ac=[]
for a in y_test:
ac.append(a)
pre=[]
for p in y_pred:
pre.append(p)
f = Figure(figsize=(5,5), dpi=100)
a = f.add_subplot(111)
a.set_ylabel(colName[2])
a.set_xlabel(colName[0]+" "+colName[1])
act,=a.plot(ac)
pred,=a.plot(pre)
a.grid()
f.legend((act,pred),('Actual Price','Predicted Price'),'upper right')
canvas = FigureCanvasTkAgg(f, self)
canvas.show()
canvas.get_tk_widget().place(x=600,y=170,width=600,height=450)
toolbar = NavigationToolbar2TkAgg(canvas, self)
toolbar.update()
canvas._tkcanvas.place(x=500,y=170,width=600,height=450)
self.mbe.insert(INSERT, metrics.mean_absolute_error(y_test, y_pred))
self.mse.insert(INSERT, metrics.mean_squared_error(y_test, y_pred))
self.rmse.insert(INSERT, np.sqrt(metrics.mean_squared_error(y_test, y_pred)))