TypeError: 'GridSearchCV' object is not callable - how do I use a pickle of an SVM (Scikit-learn)?

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?

Code:

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)
file.close()

X = pd.read_csv("ExampleSingleEmail.csv")
model(cv.transform(X))

Topic pickle scikit-learn

Category Data Science


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.