I have created an SVM in Scikit-learn for classification. It works; it prints out either 1 or 0 depending on the class. I converted it to a pickle file and tried to use it, but I am receiving this error:

TypeError: 'GridSearchCV' object is not callable
(occurs during the last line of the program)

How can I overcome this?


import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB, GaussianNB
from sklearn import svm
from sklearn.model_selection import GridSearchCV
import numpy as np
from sklearn.externals import joblib
from joblib import load
import pickle

dataframe = pd.read_csv("emails.csv")

x = dataframe["text"]
y = dataframe["spam"]
x_train,y_train = x[0:5724],y[0:5724]

cv = CountVectorizer()
features = cv.fit_transform(x_train)

tuned_parameters = {'kernel': ['rbf','linear'], 'gamma': [1e-3, 1e-4],
                 'C': [1, 10, 100, 1000]}

model = GridSearchCV(svm.SVC(), tuned_parameters)

file = open("finalized_model.sav",'rb')
model = pickle.load(file)

X = pd.read_csv("ExampleSingleEmail.csv")

1 Answer 1


Most sklearn model instances are fitted using the fit method.
Same goes here - https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html.

Change the last line to model.fit(cv.transform(X)) and it should work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.