Kaggle competition: Titanic - Machine Learning from Disaster
df_train.groupby(u ).size()<groupby>
from sklearn.linear_model import LogisticRegression
u = 'Age'
df_train.groupby(u ).size()<groupby>
x_train = pd.read_csv("/kaggle/input/titanic/train.csv")
 y_train = x_train['Survived']
x_train = x_train.drop(columns=['Survived'])
 x_test = pd.read_csv("/kaggle/input/titanic/test.csv" )
df_test.groupby(u ).size()<groupby>
def preprocessing(df):
df["Fare"] =(df["Fare"] - df["Fare"].min())/(df["Fare"].max() - df["Fare"].min())
 df["Fare"] = df["Fare"].fillna(-999)
 df["Sex"] = df["Sex"].factorize() [0]
df["Embarked"] = df["Embarked"].factorize() [0]
for i in range(len(df["Name"])) : df["Name"][i] = df["Name"][i].split(',')[0]
df["Name"] = df["Name"].factorize() [0]
df["Cabin"] = df["Cabin"].factorize() [0]
df["Age"] =(df["Age"] - df["Age"].mean())/ df["Age"].std()
df["Age"] = df["Age"].fillna(-999)
 df["Ticket"] = df["Ticket"].factorize() [0]
df_train.groupby(u ).size()<groupby>
x_train_processed = preprocessing(x_train)
 x_test_processed = preprocessing(x_test )
u = 'LastNewJob'
df_train.groupby(u ).size()<groupby>
x_train_processed = x_train.drop(columns=["Ticket"])
 x_test_processed = x_test.drop(columns=["Ticket"] )
df_train.groupby(u)['ConvertedSalary'].mean()<groupby>
model = LogisticRegression(random_state=0, max_iter=2500 ).fit(x_train_processed, y_train)
 pred = model.predict(x_test_processed)
 pred
u = 'Currency'
df_train.groupby(u ).size()<groupby>
model.score(x_train_processed, y_train )
df_test.groupby(u ).size().index<categorify>
df = pd.DataFrame(pred, columns=["Survived"])
 df.head()
<count_unique_values>
df["PassengerId"] = x_test["PassengerId"].values
df
df_train[u].nunique()<count_unique_values>
df.to_csv('predicts.csv',index=False )