Skip to content

Instantly share code, notes, and snippets.

@BinarySpoon
Last active January 12, 2021 08:06
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 BinarySpoon/08844d292344a78e7cdb75c2ab7c88da to your computer and use it in GitHub Desktop.
Save BinarySpoon/08844d292344a78e7cdb75c2ab7c88da to your computer and use it in GitHub Desktop.
# The four step process
#1 import the model you wanna use -->
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
#2 Make an instance of the model -->
lgr = make_pipeline(StandardScaler(), LogisticRegression(random_state=0))
svc = make_pipeline(StandardScaler(), SVC(random_state=0,gamma='auto'))
rf = make_pipeline(StandardScaler(), RandomForestClassifier(max_depth=2,random_state=0))
knn = make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=5))
#3 Training the model on the data (fitting) -->
lgr.fit(x_train, y_train)
svc.fit(x_train,y_train)
rf.fit(x_train,y_train)
knn.fit(x_train,y_train)
#4 Predict for new data (test) -->
lr_predict = lgr.predict(x_test)
svc_predict = svc.predict(x_test)
rf_predict = rf.predict(x_test)
knn_predict = knn.predict(x_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment