-
-
Save justmarkham/6a04f852443a0bc522afc0740dd9cb7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.preprocessing import OneHotEncoder | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.compose import make_column_transformer | |
from sklearn.pipeline import make_pipeline | |
cols = ['Parch', 'Fare', 'Embarked', 'Sex'] | |
df = pd.read_csv('http://bit.ly/kaggletrain', nrows=10) | |
X = df[cols] | |
y = df['Survived'] | |
df_new = pd.read_csv('http://bit.ly/kaggletest', nrows=10) | |
X_new = df_new[cols] | |
ohe = OneHotEncoder() | |
ct = make_column_transformer( | |
(ohe, ['Embarked', 'Sex']), | |
remainder='passthrough') | |
logreg = LogisticRegression(solver='liblinear', random_state=1) | |
pipe = make_pipeline(ct, logreg) | |
pipe.fit(X, y) | |
pipe.predict(X_new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment