Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created February 19, 2021 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/f95412e46a0d1fbe87ba132225d24bb8 to your computer and use it in GitHub Desktop.
Save amankharwal/f95412e46a0d1fbe87ba132225d24bb8 to your computer and use it in GitHub Desktop.
X_train, X_test, y_train, y_test = train_test_split(X_all, y_all, test_size = 0.2, random_state = 123)
def train_test(clf, X_train, X_test, y_train, y_test):
clf.fit(X_train, y_train)
train_acc = accuracy_score(y_train, clf.predict(X_train))
test_acc = accuracy_score(y_test, clf.predict(X_test))
return train_acc, test_acc
from sklearn.feature_extraction import DictVectorizer
vectorizer = DictVectorizer(sparse = True)
X_train = vectorizer.fit_transform(X_train)
X_test = vectorizer.transform(X_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment