Apply machine learning model to another dataset

I’m trying to get into machine learning, and I’ve been following this tutorial: https://www.analyticsvidhya.com/blog/2021/05/classification-algorithms-in-python-heart-attack-prediction-and-analysis/

Near the end, we split the dataset into training and testing using train_test_split

x = data3.drop("output", axis=1)
y = data3["output"]
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.3)

That is, we use the same dataset for training and testing, 70% for training and 30% for testing.

But how can I use another dataset to test my model ?

One scenario came to mind: “You trained your model in 250 patients, now test it against these 3 patients that we have, so we can see the chances of them having a heart attack”.

How can I, instead of splitting the data, use another csv/dataframe as a test ? Assuming this test data has the same format as the train, just fewer rows.

Answer

train_test_split(x,y,test_size=0.3) only divides data into training and testing set. After training the model on training data, you can use your other data for testing too. This function is mainly for splitting current data and you can use any data for testing purposes. You just have to make sure the attributes and the type are same as the training data. If you have to test on 3 patients, all you have to do is to pass the patients data into model.predict() function as a dataframe or an array depends on data.