How solved "ValueError: y should be a 1d array, got an array of shape () instead."?
from tkinter import *
from tkinter import ttk
from tkmacosx import Button
top = Tk()
top.title(Jobs)
top.geometry(1000x800)
line1 = LabelFrame(top, text='')
line1.pack(expand = 'yes', fill = 'both')
n = StringVar()
categorychoosen = ttk.Combobox(line1, width = 27, textvariable = n)
# Adding combobox drop down list
categorychoosen['values'] = ('Advocate','Arts','Automation Testing','Blockchain','Business Analyst',
'Web Designing')
categorychoosen.place(x=50, y=150)
categorychoosen.current()
name=Label(line3,text=Welcom to ... company,font =(Arial, 10))
name.place(x=0, y=0)
n1 = StringVar()
sectionchoosen = ttk.Combobox(line3, width = 27, textvariable = n1)
# Adding combobox drop down list
sectionchoosen['values'] = (' Computer Science',
' computer engineering',
' Information Technology',
' artificial intelligence',
' cyber security',
' computer networks',
' Information Security',
' Management Information Systems',
' Software engineering',
' data analysis',
' Data Science')
sectionchoosen.place(x=20, y=20)
sectionchoosen.current()
def model():
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from scipy.sparse import hstack
from sklearn.multiclass import OneVsRestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn import preprocessing
import numpy as np
Category= ['Advocate','Arts','Automation Testing','Web Designing']
job = categorychoosen.get()
section = sectionchoosen.get()
expert = expertchoosen.get()
language = languagechoosen.get()
# transform
p = preprocessing.LabelEncoder()
target= p.fit_transform(Category)
target.shape
wordOfjob = p.fit_transform(job)
wordOfsection = p.fit_transform(section)
#zip
features = list(zip(wordOfjob,wordOfsection))
# train_test_split
x_train, x_test, y_train, y_test = train_test_split(features,target ,random_state = 42, test_size = 0.2)
# Knn Classifier
model = OneVsRestClassifier(KNeighborsClassifier(n_neighbors=5, metric= 'euclidean' ))
model.fit(x_train,y_train)
prediction = model.predict(x_test)
# Result in GUI_Lable
jobResult = Label(line4,text=str(prediction) ,bg='light gray')
jobResult.place(x=0, y=80)
but= Button(line4,text=Start,bg='gray', command=model)
but.place(x=0, y=120)
top.mainloop()
have a problem with the error, when I execute this code, it appears like this:raise ValueError( ValueError: y should be a 1d array, got an array of shape () instead.
.
note:categorychoosen
and sectionchoosen
its Combobox in GUI python
I searched a lot and concluded that this error is always from the line model.fit(x_train,y_train)
, but I tried the solutions offered on the Internet, but no correction occurred to me. please help me. Even after adding me to target.shape
. I get the same error. The error starts when the button is pressed in the interface, i.s. when the function def model()
is started
Topic k-nn overfitting python-3.x classification python
Category Data Science