NameError: name 'clf' is not defined”

import sys,random,os,pickle

from multiprocessing import Pool

from sklearn.svm import SVC

from sklearn import metrics
from sklearn import cross_validation

from sklearn.cross_validation import train_test_split

from sklearn.externals import joblib

import pandas as pd

train = pd.read_csv("E:/training38085.csv")
test = pd.read_csv("E:/test38085.csv")
test_x = test.drop("bad_good",axis=1)

#生成validation set

val = pd.read_csv('E:/validation20000_950.csv')

train_y = train.bad_good

train_x = train.drop(['bad_good'],axis=1)

val_y = val.bad_good

val_x = val.drop(['bad_good'],axis=1)

print(test_x.shape)

print(train_x.shape)

print(val_x.shape)

def pipeline(iteration,C,gamma,random_seed):

x_train, _x , y_train, _y = train_test_split(train_x,train_y,test_size=0.4,random_state=random_seed)

print(x_train.shape)

clf = SVC(C=C,kernel='rbf',gamma=gamma,probability=True,cache_size=7000,class_weight='balanced',verbose=True,random_state=random_seed)

clf.fit(x_train,y_train)

#predict test set

pred = clf.predict_proba(test_x)
    Traceback (most recent call last):

File "", line 1, in
报错: “pred = clf.predict_proba(test_x)
NameError: name 'clf' is not defined”
上面def pipline 有clf ,为啥还会报错呢。前面的代码没有报错

http://blog.csdn.net/ustbyolanda/article/details/48736075