<jupyter_start><jupyter_text>Data preperation<jupyter_code>X = train_df.loc[:,"Age":].to_numpy() .astype('float')
y = train_df['Survived'].ravel()
print(X.shape, y.shape)
# train split test
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X ,y, test_size=0.2, random_state=0)
print(X_train.shape, y_train.shape)
print(X_test.shape,y_test.shape)
print('mean survival in train : {0: .3f}'.format(np.mean(y_train)))
print('mean survival in test : {0: .3f}'.format(np.mean(y_test)))
import sklearn
sklearn.__version__
from sklearn.dummy import DummyClassifier 
#create model
Model_dummy = DummyClassifier(strategy = 'most_frequent' ,random_state =0)
# train model 
Model_dummy.fit(X_train, y_train)
print('score for basemodel : {0: 0.2f}'.format(Model_dummy.score(X_test ,y_test)))
# performance matrix
from sklearn.metrics import accuracy_score, confusion_matrix, precision_score, recall_score 
#accuracy score
print('Accuracy score for baseline : {0: 0.2f}'.format(accuracy_score(y_test,Model_dummy.predict(X_test))))
print('confusion matrix for baseline model: \n {0}'.format(confusion_matrix(y_test, Model_dummy.predict(X_test))))
print('precision for baseline model: {0:.2f}'.format(precision_score(y_test, Model_dummy.predict(X_test))))
print('recall for baseline model \n {0}'.format(recall_score(y_test, Model_dummy.predict(X_test))))<jupyter_output>precision for baseline model: 0.00
recall for baseline model 
 0.0<jupyter_text>first kaggle Submission<jupyter_code># Conveting to the matirix
test_X = test_df.to_numpy() .astype('float')
# get prediction
predictions = Model_dummy.predict(test_X)
df_submission = pd.DataFrame({'PassengerId': test_df.index, 'Survived':predictions})
df_submission.head()
submission_data_path = os.path.join(os.path.pardir,'data','external')
submission_file_path = os.path.join(submission_data_path, 'frist_prediction.csv')
df_submission.to_csv(submission_file_path,index = False)
# writing function for submission of prediction

def get_submission_file(model ,filename):
    #converting to matrix
    test_X = test_df.to_numpy() .astype('float')
    #make prediction
    predictions = model.predict(test_X)
    #submision dataframe
    df_submission = pd.DataFrame({'PassengerId': test_df.index, 'Survived':predictions})
    # submit file
    submission_data_path = os.path.join(os.path.pardir,'data','external')
    submission_file_path = os.path.join(submission_data_path, filename)
    # write to file
    df_submission.to_csv(submission_file_path, index = False)
    
    
#get submission file
get_submission_file(Model_dummy, 'frist_prediction.csv')<jupyter_output><empty_output><jupyter_text>logistic Regression Model<jupyter_code>from sklearn.linear_model import LogisticRegression
# creating model
model_logicRegre = LogisticRegression(random_state=0)
model_logicRegre.fit(X_train, y_train)
#evaluate model
print('score the logicRegre version 1 : {0:.2f} '.format(model_logicRegre.score(X_test, y_test)))
print('confusion matrix for model_logicRegre: \n {0}'.format(confusion_matrix(y_test, model_logicRegre.predict(X_test))))
print('precision for model_logicRegre: {0:.2f}'.format(precision_score(y_test, model_logicRegre.predict(X_test))))
print('recall for model_logicRegre \n {0:.2f}'.format(recall_score(y_test, model_logicRegre.predict(X_test))))
model_logicRegre.coef_
#Submission on Logistic regression
get_submission_file(model_logicRegre, 'logicRegression_predict.csv')<jupyter_output><empty_output><jupyter_text>HypterparameterOptimisation<jupyter_code>model_logicRegre= LogisticRegression(random_state=0)
from sklearn.model_selection import GridSearchCV 
parameters = {'C':[1.0,10.0,50.0,1000.0],'penalty' : ['l1','l2']}
clf = GridSearchCV(model_logicRegre,param_grid = parameters,cv =3)
clf.fit(X_train, y_train)
clf.best_params_
print('best score : {0:.2f}'.format(clf.best_score_))
print('score for logiistic regression V 2 : {0:0.2f}'.format(clf.score(X_test, y_test)))
get_submission_file(clf, 'predict_3.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12789551503203547, 'fraction_numerical': 0.013799901429275506, 'mean_word_length': 8.100896860986547, 'pattern_counts': {'":': 1, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '459656', 'license': 'MIT', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1451, 'n_words': 251, 'path': 'notebooks/Building Predictive model.ipynb', 'repo_name': 'Emmanuelfoeh/Titanic-', 'size': '4058'}