shape( shape( ,now the data is represented in way that scikit-learn can work withand we can proceed as usualin[ ]from sklearn linear_model import logisticregression from sklearn model_selection import train_test_split x_trainx_testy_trainy_test train_test_split(xyrandom_state= logreg logisticregression(logreg fit(x_trainy_trainprint("test score{ }format(logreg score(x_testy_test))out[ ]test score in this examplewe called get_dummies on dataframe containing both the training and the test data this is important to ensure categorical values are represented in the same way in the training set and the test set imagine we have the training and test sets in two different data frames if the "private employeevalue for the workclass feature does not appear in the test setpandas will assume there are only three possible values for this feature and will create only three new dummy features now our training and test sets have different numbers of featuresand we can' apply the model we learned on the training set to the test set anymore even worseimagine the workclass feature has the values "government employeeand "private employeein the training setand "self employedand "self employed incorporatedin the test set in both casespandas will create two new dummy featuresso the encoded data frames will have the same number of features howeverthe two dummy features have entirely different meanings in the training and test sets the column that means "government employeefor the training set would encode "self employedfor the test set if we built machine learning model on this data it would work very badlybecause it would assume the columns mean the same things (because they are in the same positionwhen in fact they mean very different things to fix thiseither call get_dummies on dataframe that contains both the training and the test data pointsor make sure that the column names are the same for the training and test sets after calling get_dummiesto ensure they have the same semantics categorical variables