<jupyter_start><jupyter_text>Analyze data<jupyter_code>sns.countplot(x = 'Survived', data  = titanic_data)
sns.countplot(x = "Survived", hue = "Sex", data = titanic_data)
sns.countplot(x = "Survived", hue = "Pclass", data = titanic_data )
titanic_data["Age"].plot.hist()
titanic_data["Fare"].plot.hist(bins = 20, figsize = (10,5))
titanic_data.info()
sns.countplot(x = "SibSp", data = titanic_data)
sns.countplot(x = "Parch", data = titanic_data)<jupyter_output><empty_output><jupyter_text>Data Wrangling<jupyter_code>#check if there is any null values in the dataframe
titanic_data.isnull()
titanic_data.isnull().sum()
sns.heatmap(titanic_data.isnull(), yticklabels = False, cmap= "viridis")
sns.boxplot(x = "Pclass", y = "Age",data = titanic_data)

titanic_data.drop("Cabin", axis = 1, inplace = True)
titanic_data.head()

titanic_data.dropna(inplace = True)
sns.heatmap(titanic_data.isnull(),yticklabels = False, cbar = False)
titanic_data.isnull().sum()
#converting string data into categorical data

sex = pd.get_dummies(titanic_data["Sex"],drop_first = True)
sex.head()
emb = pd.get_dummies(titanic_data["Embarked"],drop_first = True)
emb.head()
pcl = pd.get_dummies(titanic_data["Pclass"],drop_first = True)
pcl.head()
#concating the converted columns and the original dataframe
titanic_data = pd.concat([titanic_data, sex,emb,pcl],axis = 1)

titanic_data.head()
#dropping unnecessary columns
titanic_data.drop(["Sex","Embarked","PassengerId","Name","Ticket"],axis=1, inplace = True)
titanic_data.head()
titanic_data.drop("Pclass",axis =1 , inplace = True)<jupyter_output><empty_output><jupyter_text>Train Data<jupyter_code>#split input and output data
X = titanic_data.drop("Survived", axis = 1)
Y = titanic_data["Survived"]
#split train and test_data

from sklearn.model_selection import train_test_split
#from sklearn.cross_validation import train_test_split
X_train, X_test, Y_train,Y_test = train_test_split(X,Y,test_size = 0.3,random_state = 1)
from sklearn.linear_model import LogisticRegression
#create a Logistic Regression model and train it
logmodel = LogisticRegression()

logmodel.fit(X_train, Y_train)
#use the trained model to make predictions on test data 
predictions = logmodel.predict(X_test)
#get classification report and accuracy
from sklearn.metrics import classification_report
classification_report(Y_test, predictions)
from sklearn.metrics import confusion_matrix
confusion_matrix(Y_test, predictions)
from sklearn.metrics import accuracy_score
accuracy_score(Y_test,predictions)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12313139260424863, 'fraction_numerical': 0.0051140833988985055, 'mean_word_length': 8.0177304964539, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '156793', 'license': 'Apache-2.0', 'n_tokens_mistral': 956, 'n_tokens_neox': 920, 'n_words': 187, 'path': 'Titanic_LogisticRegression.ipynb', 'repo_name': 'mesakarghm/MachineLearningBasics', 'size': '2542'}