<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vignesh Venkat on Medium]]></title>
        <description><![CDATA[Stories by Vignesh Venkat on Medium]]></description>
        <link>https://medium.com/@vignesh-v2003?source=rss-3cb5e4f922c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6L3qM6FIBNY9r9f9RCFjYg.jpeg</url>
            <title>Stories by Vignesh Venkat on Medium</title>
            <link>https://medium.com/@vignesh-v2003?source=rss-3cb5e4f922c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:45:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vignesh-v2003/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Titanic Survival Project — Pop Culture to Data Science]]></title>
            <link>https://medium.com/analytics-vidhya/titanic-survival-project-pop-culture-to-data-science-55e8721ef0a8?source=rss-3cb5e4f922c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/55e8721ef0a8</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[fun]]></category>
            <dc:creator><![CDATA[Vignesh Venkat]]></dc:creator>
            <pubDate>Thu, 11 Mar 2021 14:32:10 GMT</pubDate>
            <atom:updated>2021-03-16T17:00:13.547Z</atom:updated>
            <content:encoded><![CDATA[<h3>Titanic Survival Project — Pop Culture to Data Science</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NB7UEm8AzKh6d-jNrJCBhw.jpeg" /><figcaption>Titanic — Picture (creds. wallpaper flare)</figcaption></figure><p>The unsinkable ship that sunk on its maiden voyage. Debatable movie. The tragic Titanic. By using the data that is provided on Kaggle, we as data scientists can apply a lot of our knowledge to a, relatively clean, dataset. The dataset is ripe for EDA (Exploratory Data Analysis), Data Cleaning techniques, and Machine Learning algorithms. Data Science is not something that is limited to PhDs and academia. Anyone can do it, and I hope to share my methodology in solving this kaggle challenge. The titanic is embedded in our popular culture, so it&#39;s easy to pick up this data set and start to tinker. So let&#39;s get started!</p><h3>Data Exploration</h3><h4>Importing and Basic Setup</h4><p>So firstly, I imported the packages I thought I would need for the project:</p><pre><strong>import</strong> <strong>pandas</strong> <strong>as</strong> <strong>pd</strong> <br><strong>import</strong> <strong>numpy</strong> <strong>as</strong> <strong>np</strong><br><strong>import</strong> <strong>matplotlib.pyplot</strong> <strong>as</strong> <strong>plt</strong><br><strong>import</strong> <strong>sklearn</strong> <br><strong>import</strong> <strong>seaborn</strong> <strong>as</strong> <strong>sns</strong></pre><p>I used pandas &amp; NumPy for data preparation and mutation while, if I wanted to, I would visualize with Matplotlib and seaborn.</p><pre>train_df = pd.read_csv(&#39;train.csv&#39;) <br>test_df = pd.read_csv(&#39;test.csv&#39;)</pre><pre>tempdf = pd.read_csv(&#39;gender_submission.csv&#39;) <em>#Might come useful later</em></pre><p>I loaded in the data and set aside a temporary DataFrame for the solutions to the test DataFrame.</p><pre>train_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V2gu5sIjd15pCinQaxLN5g.png" /></figure><pre>test_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*pLhMmYFBzg1cPR_0PZ1gnQ.png" /></figure><p>what jumps out immediately, is the fact that there isn&#39;t a survived column in the test DataFrame. Although this is to be expected, as the survived column is what we need to predict. By using features that lay in the DataFrame, we should be able to predict the people who survived the Titanic tragedy.</p><h4>Exploring the Data Further</h4><p>Firstly, I start my analysis of the data by understanding its contents. It is important to see how many NaN/null values lay in the data, as well as, how many unique values are present in each of the columns. Thus I start by writing:</p><pre>train_df.nunique()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*WYB_1vvePp6TgBiHPepiDA.png" /></figure><p>Now we can clearly see that we have 891 passengers in our training data set. As we expected, there are only 2 survived unique values, as you can only survive or not survive. There are 3 classes for passengers: 1, 2, or 3. There are 2 sexes and so on. The nunique() function allows us to see the number of unique values in each column. However, to see how many nan values there are, I coded:</p><pre>train_df.isnull().sum()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*i7Zuk3lx838LIEL2-K7FWA.png" /></figure><p>This is quite intriguing, as the cabin column has become obsolete. In the 891 columns, 687 of the rows are missing. Therefore I dropped the series from the DataFrame:</p><pre>train_df = train_df.drop(&#39;Cabin&#39;, axis = 1)<br>train_df.head()</pre><p>Although I concede that you can extrapolate the data from other columns, I found it to generally not have that large of an impact compared to other features. Although we have done some minimal cleaning to the dataset, there are 177 “ages” that are not found in the dataset.</p><h4>Train Data Cleaning &amp; Preparation</h4><p>I started with filling the Age null values with the mean:</p><pre>train_df[&#39;Age&#39;].fillna(train_df[&#39;Age&#39;].mean(), inplace = <strong>True</strong>)</pre><p>By filling with the mean, we wouldn’t disturb the integrity of the dataset. Although the median may be slightly shifted, the mean would remain the same and, in theory, we would be able to use the column in our models. To round out the cleaning of the data, I simply dropped the rows that had the null values in the embarked data by:</p><pre>train_df = train_df.dropna(subset = [&#39;Embarked&#39;])</pre><p>Then to confirm that all of the null values were indeed removed, I checked by running:</p><pre>train_df.isnull().sum()</pre><p>and voila:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/150/1*B8ssw-c8duCsuUzc3-KuTg.png" /></figure><p>Now that we have removed all the null values, we can proceed with feature engineering and optimization.</p><h4>Feature Engineering</h4><p>To start with, let us create a new column called Travelling Alone. Right now there are only the SibSp and Parch columns, which are discussing Siblings, Spouses, Parents &amp; Children. Using the data we can extrapolate the Travelling Alone column. Using the column we can see if there are any changes to the survival probability if you are alone or not.</p><pre>train_df[&#39;Travelling Alone&#39;] = train_df.apply(<strong>lambda</strong> row: row.SibSp == 0 &amp; row.Parch == 0, axis = 1)<br><br>train_df.loc[train_df[&#39;Travelling Alone&#39;] == <strong>True</strong>, &#39;Travelling Alone&#39;] = 1<br><br>train_df.loc[train_df[&#39;Travelling Alone&#39;] == <strong>False</strong>, &#39;Travelling Alone&#39;] = 0</pre><pre>train_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8DKVTjRgoQHEuqirOzb6g.png" /></figure><p>By using a lambda function, we can check if the conditions are met, and if so then we can add it to the Travelling Alone column. However, using a lambda yields a boolean type. Therefore, we use Pandas’ .loc[] operator to mutate the data into an integer data type. Although you do not necessarily have to do this step, I found it useful to maintain similar conventions throughout the project.</p><p>During this project, I used Scikit-Learn and their models do not accept strings. Therefore, it would be prudent to remove columns that contain strings or chars. Name, Ticket, Embarked, Sex all have strings or chars in the column. For Name and Ticket, as they are not needed in the models, we can simply remove them.</p><pre>train_df = train_df.drop([&#39;Ticket&#39;, &#39;Name&#39;], axis = 1)</pre><pre>train_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*ruJYJE0Erqk93_6wfgR6pQ.png" /></figure><p>We already have a way of distinguishing between passengers, and that is simply through used their Passenger ID. However, sex and where they embarked from are important columns. They could be vital to the machine learning models, as they are categorical variables. By using Pandas’ .loc[], we can change the Sex column from string to integer.</p><pre>train_df.loc[train_df[&#39;Sex&#39;] == &#39;male&#39;, &#39;Sex&#39;] = 1<br>train_df.loc[train_df[&#39;Sex&#39;] == &#39;female&#39;, &#39;Sex&#39;] = 0</pre><pre>train_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*79P_768jmVPQov8kX8P2rw.png" /></figure><p>Now that we have assigned males to the number 1, and females to the number 0, we can move on to the embarked column. The embarked column consists of 3 categories. S, C, and Q. Each a port from where the passenger departed from. C = Cherbourg, Q = Queenstown, S = Southampton. I set Queenstown to 1, Southampton to 2, and Cherbourg to 3.</p><pre>train_df.loc[train_df[&#39;Embarked&#39;] == &#39;Q&#39;, &#39;Embarked&#39;] = 1<br><br>train_df.loc[train_df[&#39;Embarked&#39;] == &#39;S&#39;, &#39;Embarked&#39;] = 2<br><br>train_df.loc[train_df[&#39;Embarked&#39;] == &#39;C&#39;, &#39;Embarked&#39;] = 3</pre><p>This way, all of the data is in terms of integers and there would be no issue working with the package: sci-kit learn. Just as we extrapolated the Travelling Alone column, we can create another feature called Family Size in a similar fashion. By using a lambda function, we can access the rows: SibSp and Parch to create a new column.</p><pre>train_df[&#39;Family Size&#39;] = train_df.apply(<strong>lambda</strong> row: row.SibSp + row.Parch, axis = 1)</pre><pre>train_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*FWGdVJ97Ok1UsuJMGq2rmw.png" /></figure><p>By creating a new column, we can monitor the trends that Family Size might have about the survival rate.</p><p>Now that we have cleaned our data and created new columns to analyze, we must do the same for our test DataFrame. Our features for the Test DataFrame and Training DataFrame must be identical to ensure that no errors come up during the training and testing phase of our model.</p><pre>test_df = test_df.drop([&#39;Ticket&#39;, &#39;Name&#39;, &#39;Cabin&#39;], axis = 1)<br><br>test_df[&#39;Age&#39;].fillna(test_df[&#39;Age&#39;].mean(), inplace = <strong>True</strong>)<br>test_df = test_df.dropna(subset = [&#39;Embarked&#39;])<br><br>test_df[&#39;Travelling Alone&#39;] = test_df.apply(<strong>lambda</strong> row: row.SibSp == 0 &amp; row.Parch == 0,axis = 1)<br><br>test_df.loc[test_df[&#39;Travelling Alone&#39;] == <strong>True</strong>, &#39;Travelling Alone&#39;] = 1<br><br>test_df.loc[test_df[&#39;Travelling Alone&#39;] == <strong>False</strong>, &#39;Travelling Alone&#39;] = 0<br><br>test_df.loc[test_df[&#39;Sex&#39;] == &#39;male&#39;, &#39;Sex&#39;] = 1<br><br>test_df.loc[test_df[&#39;Sex&#39;] == &#39;female&#39;, &#39;Sex&#39;] = 0<br><br>test_df[&#39;Family Size&#39;] = test_df.apply(<strong>lambda</strong> row: row.SibSp + row.Parch, axis = 1)</pre><pre>test_df.loc[test_df[&#39;Embarked&#39;] == &#39;Q&#39;, &#39;Embarked&#39;] = 1<br><br>test_df.loc[test_df[&#39;Embarked&#39;] == &#39;S&#39;, &#39;Embarked&#39;] = 2<br><br>test_df.loc[test_df[&#39;Embarked&#39;] == &#39;C&#39;, &#39;Embarked&#39;] = 3</pre><pre>test_df[&#39;Fare&#39;].fillna(test_df[&#39;Fare&#39;].mean(), inplace = <strong>True</strong>)</pre><h3>Machine Learning Models</h3><p>Now, let&#39;s move onto the good stuff. As this is my first true Data Science project, I would appreciate it if you guys gave me feedback to alter and tweak my project in the comments!</p><p>I start by looking at my train and test DataFrames one more time, just to see if everything is in sync and ready to go!</p><pre>train_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*N3VTRbO22oIo04vq3CkYzg.png" /></figure><pre>test_df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*xeGMxSLUpAiMlIBwXCthtg.png" /></figure><p>It looks like our data is in tiptop shape and if we do need to edit anything, we can just do it along the way. To start the Machine Learning process, we have to specify our features:</p><pre>features = [&#39;Sex&#39;, &#39;SibSp&#39;, &#39;Parch&#39;, &#39;Travelling Alone&#39;, &#39;Family Size&#39;, &#39;Embarked&#39;, &#39;Pclass&#39;]<br><br>Y = train_df[&#39;Survived&#39;]<br>X = train_df[features]<br><br>X_test = test_df[features]</pre><p>The features I selected were Sex, SibSp, Parch, Travelling Alone, Family Size, Embarked, and the class of the passengers. Notably, I did not include Age and Fare, as I found while testing that those tended to make my models overfit. It might be because 731 out of the 891 passengers only paid between 0–50 pounds and that I cleared the nan values from the age by using the mean. However, due to those circumstances, I chose not to use those features. To ensure that there were no null values I, once again, tested the train and test DataFrames:</p><pre>X_test.isnull().sum()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*7sjrqViKjmU-CBkSWOvqWw.png" /></figure><pre>X.isnull().sum()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*vmMvwZg89TmHDvhd8xKCbg.png" /></figure><p>Now that any suspicions of nan values being present have been wiped away, let&#39;s start modeling.</p><h4>Random Forest Classifier</h4><p>The first up on our list is the Random Forest Classifier. All of the models I will be using are compatible with the sklearn package. I start by calling the package:</p><pre><strong>from</strong> <strong>sklearn.ensemble</strong> <strong>import</strong> RandomForestClassifier</pre><pre>rf = RandomForestClassifier(n_estimators = 100,<br>                           n_jobs = -1,<br>                           oob_score = <strong>True</strong>,<br>                           bootstrap = <strong>True</strong>,<br>                           random_state = 42)</pre><p>I assign the RandomForestClassifier object to a variable that is easy to type out because as Bill Gates said:</p><blockquote>“I will always choose a lazy person to do a difficult job because a lazy person will find an easy way to do it.”</blockquote><p>I created a model variable and “fitted” the model:</p><pre>rfm = rf.fit(X,Y)</pre><p>Then I scored the model:</p><pre>rfm.score(X,Y)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*JEtln5X1V-2HPArRfcQG0g.png" /></figure><p>The relationship between the features and survival rate, within the Train DataFrame, is around 84%. However, Decision Tree-based algorithms are known for overfitting, so the value might not be accurate for the test data.</p><p>Therefore, I try to use a better technique to accurately judge the relationship between the Training and Testing values:</p><pre><strong>from</strong> <strong>sklearn.model_selection</strong> <strong>import</strong> cross_val_score</pre><pre>accuracyRFM = cross_val_score(estimator=rfm, X = X, y = Y, cv=5) accuracyRFM.mean()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*HzYWFGTFnLRfeTcfV9Sg_Q.png" /></figure><p>We get a 78.4% correlation, which seems more realistic for a pre-tuned model.</p><p>I go on to make an array for the predictions which is coded as such:</p><pre>predictions = rfm.predict(X_test)</pre><pre>predictions</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*UZHCPxNszxxO1R4xfsY9kg.png" /></figure><h4>Support Vector Machine Classifier</h4><p>Next, let’s try the SVM Classifier through sci-kit learn! We will go through the same steps:</p><pre><strong>from</strong> <strong>sklearn</strong> <strong>import</strong> svm<br>svms = svm.SVC()</pre><pre>s = svms.fit(X,Y)</pre><pre>svms.score(X,Y)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*KFEUIiwo0iHg25HjRlgyLw.png" /></figure><p>This time, using the .score() function, we received a rough estimate of 81%. Now let us use the cross_val_score function:</p><pre>accuracySVM = cross_val_score(estimator=s, X = X, y = Y, cv=5)<br>accuracySVM.mean()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*jBLLo8U5f9QCmtJBGgv3BQ.png" /></figure><p>Even though our scikit-learn score was technically lower, our cross-validation score came out to be higher. SVMs seem to be less prone to overfitting compared to Decision Tree-based models.</p><p>Just like the last model, I created a prediction array:</p><pre>predictions = svms.predict(X_test)<br>predictions</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*WPqXAjhcfGxYgAHb9jMz9Q.png" /></figure><h4>Logistic Regression</h4><p>I ended up doing a couple of other models: Decision trees, AdaBoostClassifier, GradientBoostClassifier, and KNN, but I find showing you the same process would only serve to make this article longer and more redundant. So I’ll show you the third model I used: Logistic Regression. Although Regression models usually serve for prediction-type problems, Logistic Regression is used for classification-based data sets. So just like last time:</p><pre><strong>from</strong> <strong>sklearn.linear_model</strong> <strong>import</strong> LogisticRegression</pre><pre>lr = LogisticRegression()</pre><pre>l = lr.fit(X,Y)</pre><pre>l.score(X,Y)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*Rw13yPzzFkkGN3B7qnXRUg.png" /></figure><p>Our sci-kit learn score came out to around 81, however, we know better than to rely on one source of information:</p><pre>accuracySVM = cross_val_score(estimator=l, X = X, y = Y, cv=5)<br>accuracySVM.mean()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*UhOSPGc0HqWCmqmNVoSeqA.png" /></figure><p>Our cross-validation score comes out to roughly 79%. There is only a 1% drop between the sklearn score and the cross-validation score. This serves to tell us that Logistic Regression is also not hampered by overfitting like Decision Trees. Just like the last couple of models, I create predictions array:</p><pre>predictions = l.predict(X_test)</pre><pre>predictions</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*CQmbLHJFkku1APfHcXHrrQ.png" /></figure><h3>Tuning the Models</h3><p>In the last section, we ended up using the base models and we had little to no control over the models themselves. Now we are going to directly access the parameters of the models, and alter them to find the best parameters and models.</p><p>We will start by importing some important packages:</p><pre><strong>from</strong> <strong>pprint</strong> <strong>import</strong> pprint</pre><pre><strong>from</strong> <strong>sklearn.model_selection</strong> <strong>import</strong> GridSearchCV, StratifiedKFold<br><strong>from</strong> <strong>sklearn</strong> <strong>import</strong> linear_model, decomposition<br><strong>from</strong> <strong>sklearn.preprocessing</strong> <strong>import</strong> StandardScaler</pre><pre>kfold = StratifiedKFold(n_splits=10)</pre><p>We use GridSearchCV to find the best possible model for our data.</p><h4>Hyper-Parameter Tuning for Random Forest Classifier</h4><pre>rf_param_grid = <br>{&#39;max_features&#39; : [0.1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], &#39;min_samples_split&#39;: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], &#39;min_samples_leaf&#39;: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 150]}<br><br>best_rfc = GridSearchCV(rfc, param_grid = rf_param_grid, cv = kfold, scoring = &#39;accuracy&#39;, n_jobs  = 4, verbose = 2)<br><br>best_rfc.fit(X,Y)<br><br>pprint(best_rfc.best_score_)<br><br>best_rfc = best_rfc.best_estimator_</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*32TQxvLfo9P_CtrLIW_jpA.png" /></figure><p>To start, we have to research what are the hyper-parameters of the model. To do this you do a simple google search and go to the documentation <a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html">here</a>. By changing the max features, minimum sample split, and leaf I have more control over my classification model. I plug in my parameter grid into the GridCV function along with how I want my scoring done. Then I proceed to use the GridSearchCV object to tune the Random Forest Classification model. I print the best score which comes out to 80.1%, a significant upgrade to the 78% with the base-line model. Then we assign the best_estimator_, which consists of the best parameters, to the variable: best_rfc.</p><h4>Hyper-Parameter Tuning for Support Vector Machine Classification</h4><p>Using a similar procedure as the last model, we code:</p><pre>svmc = SVC(probability = <strong>True</strong>)<br><br>svmc_param_grid = {&quot;kernel&quot;: [&#39;rbf&#39;], &#39;gamma&#39;: [0.001, 0.01, 0.1, 1, 10], &#39;C&#39;: [0.01, 0.1, 1, 10, 50, 100, 500, 1000, 5000, 10000]}<br><br>best_svmc = GridSearchCV(svmc, param_grid = svmc_param_grid, cv = kfold, scoring = &#39;accuracy&#39;, n_jobs = 4, verbose = 2)<br><br>best_svmc.fit(X,Y)<br><br>pprint(best_svmc.best_score_)<br><br>best_svmc = best_svmc.best_estimator_</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*raRupeRepF9BHqdq0XU13w.png" /></figure><p>The support vector machine outputs a best score of 80.1% as well. There is no significant increase from the baseline model.</p><h4>Hyper-Parameter Tuning for Logistic Regression</h4><p>Just like the models, I wouldn&#39;t want it to be redundant, so I will show one more case of hyper-parameter tuning:</p><pre>lr = LogisticRegression()<br><br>lr_param_grid = {&#39;penalty&#39;: [&#39;l1&#39;,&#39;l2&#39;], &#39;C&#39;: [50, 10, 1.0, 0.1, 0.01], &#39;solver&#39;: [&#39;newton-cg&#39;, &#39;lbfgs&#39;, &#39;liblinear&#39;, &#39;sag&#39;, &#39;saga&#39;]}<br><br>best_lr = GridSearchCV(lr, param_grid = lr_param_grid, cv = kfold, scoring = &#39;accuracy&#39;, n_jobs = 4, verbose = 2)<br><br>best_lr.fit(X,Y)<br><br>pprint(best_lr.best_score_)<br><br>best_lr = best_lr.best_estimator_</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fcVfbxn2vskiROtSMsvfzg.png" /></figure><p>The Logistic Regression Model outputted a best score of 80%, up by 1% from the baseline model.</p><h3>Combining all of the Tuned Models into an Ensemble</h3><p>Now that we have tuned out models, it is time to string them together. To do this, we are going to use the Voting Classifier that resides in the ensemble subpackage of sklearn:</p><pre><strong>from</strong> <strong>sklearn.ensemble</strong> <strong>import</strong> VotingClassifier</pre><p>Then we will move on to stringing the tuned models together:</p><pre>stringClassifier = VotingClassifier(estimators=[(&#39;rfc&#39;, best_rfc),(&#39;svc&#39;, best_svmc), (&#39;adac&#39;,best_abc),(&#39;gbc&#39;,best_gbc), (&#39;knn&#39;, best_knn), (&#39;lr&#39;, best_lr)], voting=&#39;soft&#39;, n_jobs=4)</pre><pre>stringClassifier = stringClassifier.fit(X, Y)</pre><pre>stringClassifier.score(X,Y)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/163/1*c1HTCY-Ee5OGQQbviA0CrA.png" /></figure><p>Using the Voting Classifier function, we can garner an 82.5% prediction rate. Now we simply use the array function to create our predictions:</p><pre>predictions = votingC.predict(X_test)<br>predictions</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*4vPE6fAHHHeD6McNwTwb1g.png" /></figure><p>Finally, we write a CSV so that we can submit our findings:</p><pre>Survived = pd.Series(stringClassifier.predict(X_test), name=&quot;Survived&quot;)<br><br>results = pd.concat([IDtest,Survived],axis=1)<br><br>results.to_csv(&quot;results.csv&quot;,index=<strong>False</strong>)</pre><h3>Conclusion</h3><p>Although the Titanic Dataset may not be representative of real-world data, there is certainly a lot to be learned through the data set. I am a big proponent of learning through practice, and for that, I will always be thankful for this dataset. In many ways, I was able to apply my skills from the Machine Learning by Andrew Ng course (highly recommend) and others. When you’re in a course, you’re given tidbits of information but in a project, you are giving nothing. You &amp; the data. That&#39;s it. I hoped I could inspire a few of you to pick up the dataset and try to learn techniques that would otherwise be left untouched. I&#39;m certainly not an expert in Machine Learning so I would be thankful for feedback or any questions! Thank you guys for reading!</p><h4>Important Links</h4><p><a href="https://www.kaggle.com/c/titanic">Titanic - Machine Learning from Disaster</a></p><p><a href="https://www.wallpaperflare.com/white-and-black-ship-titanic-vintage-ship-wallpaper-255721">https://www.wallpaperflare.com/white-and-black-ship-titanic-vintage-ship-wallpaper-255721</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55e8721ef0a8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/titanic-survival-project-pop-culture-to-data-science-55e8721ef0a8">Titanic Survival Project — Pop Culture to Data Science</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>