mardi 24 mai 2022

how solved "ValueError: Expected 2D array, got scalar array instead:"?

the image of interface the program enter image description here

from tkinter import *
from tkmacosx import Button
from tkinter import ttk
top = Tk('1000','1000')
top.title("Candidate Prediction")

top.configure(bg='light gray')

cvLabel=Label(top,text="Choose your department",bg='light gray').grid(row=0,column=0)

#Section selection
n = StringVar()
categorychoosen = ttk.Combobox(top, width = 27, textvariable = n)
  
# Adding combobox drop down list
categorychoosen['values'] = (' Computer Science', 
                          ' computer engineering',
                          ' Information Technology',
                          ' artificial intelligence',
                          ' cyber security',
                          ' computer networks',
                          ' Information Security',
                          ' Management Information Systems',
                          ' Software engineering',
                          ' data analysis',
                          ' Data Science')
  
categorychoosen.grid(row=1, column=2)
categorychoosen.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

    #Data
    resume = pd.read_csv(r'/Users/asma/Desktop/UpdatedResumeDataSet.csv')
    
    x = resume['Resume'].values
    y = resume['Category'].values
    #transform
    word = TfidfVectorizer(sublinear_tf=True, stop_words='english')
    word.fit(x)
    wordFeatures = word.transform(x)
    
    #KNN 
    model = KNeighborsClassifier(n_neighbors=5, metric= 'euclidean')
    
    model.fit(wordFeatures,y)
    x_test = n.get()
    y_pred = model.predict(x_test)
  
    #Result
    jobR = Label(top,text=str(y_pred) ,bg='light gray').grid(row=4,column=2)


but= Button(top,text="Start",bg='gray', command=model).grid(row=3,column=0)


job=Label(top,text="The Category is :",bg='light gray').grid(row=4,column=0)




top.mainloop()

The idea of the program is simple, I just want the user to choose the department, then the department chosen by the user is tested in the KNN algorithm with a set of resume data. Here is a picture of part of the resume data enter image description here

I want the output to be defining for me which of the categories the KNN process has chosen. For example, to exit one of the appropriate categories with the section that the user has chosen. But I have an error when I press the start button. What I understood is that the error existing in the model() function. the error is : ValueError: Expected 2D array, got scalar array instead: array= Information Technology. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.




Aucun commentaire:

Enregistrer un commentaire