I was trying to implement support vector machine in python. Given 2000 sets of input train data and test data, i tried to print the accuracy of prediction of y.
def method1_SVM():
X, y = trainDataImport()
kf = KFold(n_splits=10)
acc = []
for train_index, test_index in kf.split(X):

    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]

    Y_pred = computeSVM(10,'rbf', 0.001, X_train, y_train, X_test)
    print(evaluation(y_test, Y_pred))
Then i got results below

0.885
None
0.865
None
0.885
None
0.87
None
0.875
None
0.89
None
0.855
None
0.86
None
0.885
None
0.865
None

Next, I tried this function below.

def method1_SVM():
X, y = trainDataImport()
kf = KFold(n_splits=10)
acc = []
for train_index, test_index in kf.split(X):

    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]

    Y_pred = computeSVM(10,'rbf', 0.001, X_train, y_train, X_test)
    acc.append(evaluation(y_test, Y_pred))

return acc
#def main():
array = method1_SVM()
print(array)

This time, I returned list of accuracy from this function. And after that, call method1_SVM() function from main function. Lets see the output.

0.885
0.865
0.885
0.87
0.875
0.89
0.855
0.86
0.885
0.865
[None, None, None, None, None, None, None, None, None, None]

Still I got 10 "None" of list.

Now lets look at the evaluation function.

#'def evaluation(y_real, y_pred):
acc = accuracy_score(y_real, y_pred)
print(acc)

There is already print function in it.
I fixed like this.

#'def evaluation(y_real, y_pred):
acc = accuracy_score(y_real, y_pred)
return acc

Now it worked!!!

0.885
0.865
0.885
0.87
0.875
0.89
0.855
0.86
0.885
0.865

In short, I implemented like this.

def function():
print(value)
def main():
print(function)

There is nothing to print in main function.

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.