Search code examples
machine-learningclassification

Test a model on another dataset?


I need to evaluate the ML model on another dataset but i don't know what it fully means. I have an idea but i am not sure. Let's say we have:

  • X_train, X_test, y_train, y_test split from X,Y for the first model
  • X_train_2, X_test_2, y_train_2, y_test_2 split from X2, 2 for the 2nd model

After training both model with model.fit, how do i test them on the other database? Is it:

from sklearn.svm import SVC


#training on the first model
svm.fit(X, Y)

#test on  the 2nd model
y_pred = svm.predict(X_test_2)

#evaluate accuracy
print(accuracy_score(y_test, y_pred))

It seems simple but i am really confused, i would appreciate some explanations.


Solution

  • Testing on another dataset, say X2, y2, does not mean you need to split this second dataset into training & test subsets, as you have done for your original X & y. Once you have fitted your model, say svm, in X as you show, you simply predict on X2 and compare with the labels in y2:

    # predict on the 2nd dataset X2
    y_pred = svm.predict(X2)
    
    # evaluate accuracy
    print(accuracy_score(y2, y_pred))