Update code listings
This commit is contained in:
+9
-15
@@ -1,15 +1,9 @@
|
||||
>>> titanic["Age"].notna()
|
||||
Name
|
||||
Braund, Mr. Owen Harris True
|
||||
Cumings, Mrs. John Bradley (Florence Briggs Thayer) True
|
||||
Heikkinen, Miss. Laina True
|
||||
Futrelle, Mrs. Jacques Heath (Lily May Peel) True
|
||||
Allen, Mr. William Henry True
|
||||
...
|
||||
Montvila, Rev. Juozas True
|
||||
Graham, Miss. Margaret Edith True
|
||||
Johnston, Miss. Catherine Helen "Carrie" False
|
||||
Behr, Mr. Karl Howell True
|
||||
Dooley, Mr. Patrick True
|
||||
Name: Age, Length: 891, dtype: bool
|
||||
>>> valid_ages = titanic[titanic["Age"].notna()]
|
||||
>>> titanic = pd.read_csv(URL, index_col="Name")
|
||||
>>> titanic.head()
|
||||
PassengerId ... Embarked
|
||||
Name ...
|
||||
Braund, Mr. Owen Harris 1 ... S
|
||||
Cumings, Mrs. John Bradley (Florence Briggs Tha... 2 ... C
|
||||
Heikkinen, Miss. Laina 3 ... S
|
||||
Futrelle, Mrs. Jacques Heath (Lily May Peel) 4 ... S
|
||||
Allen, Mr. William Henry 5 ... S
|
||||
|
||||
+15
-2
@@ -1,2 +1,15 @@
|
||||
titanic[(titanic["Sex"] == "female") &
|
||||
(titanic["Pclass"] == 3)]["Survived"].mean()
|
||||
>>> titanic["Age"].notna()
|
||||
Name
|
||||
Braund, Mr. Owen Harris True
|
||||
Cumings, Mrs. John Bradley (Florence Briggs Thayer) True
|
||||
Heikkinen, Miss. Laina True
|
||||
Futrelle, Mrs. Jacques Heath (Lily May Peel) True
|
||||
Allen, Mr. William Henry True
|
||||
...
|
||||
Montvila, Rev. Juozas True
|
||||
Graham, Miss. Margaret Edith True
|
||||
Johnston, Miss. Catherine Helen "Carrie" False
|
||||
Behr, Mr. Karl Howell True
|
||||
Dooley, Mr. Patrick True
|
||||
Name: Age, Length: 891, dtype: bool
|
||||
>>> valid_ages = titanic[titanic["Age"].notna()]
|
||||
|
||||
+2
-4
@@ -1,4 +1,2 @@
|
||||
male_passengers = titanic[titanic["Sex"] == "male"]
|
||||
female_passengers = titanic[titanic["Sex"] == "female"]
|
||||
valid_male_ages = male_passengers[titanic["Age"].notna()]
|
||||
valid_female_ages = female_passengers[titanic["Age"].notna()]
|
||||
titanic[(titanic["Sex"] == "female") &
|
||||
(titanic["Pclass"] == 3)]["Survived"].mean()
|
||||
|
||||
+4
-1
@@ -1 +1,4 @@
|
||||
>>> from sklearn.linear_model import LinearRegression
|
||||
male_passengers = titanic[titanic["Sex"] == "male"]
|
||||
female_passengers = titanic[titanic["Sex"] == "female"]
|
||||
valid_male_ages = male_passengers[titanic["Age"].notna()]
|
||||
valid_female_ages = female_passengers[titanic["Age"].notna()]
|
||||
|
||||
+1
-5
@@ -1,5 +1 @@
|
||||
from sklearn.linear_model import LogisticRegression
|
||||
from sklearn.naive_bayes import GaussianNB
|
||||
from sklearn.linear_model import Perceptron
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
from sklearn.ensemble import RandomForestClassifier
|
||||
>>> from sklearn.linear_model import LinearRegression
|
||||
|
||||
+5
-7
@@ -1,7 +1,5 @@
|
||||
Model
|
||||
Score
|
||||
0.854749 Decision Tree
|
||||
0.854749 Random Forest
|
||||
0.787709 Logistic Regression
|
||||
0.770950 Naive Bayes
|
||||
0.743017 Perceptron
|
||||
from sklearn.linear_model import LogisticRegression
|
||||
from sklearn.naive_bayes import GaussianNB
|
||||
from sklearn.linear_model import Perceptron
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
from sklearn.ensemble import RandomForestClassifier
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Model
|
||||
Score
|
||||
0.854749 Decision Tree
|
||||
0.854749 Random Forest
|
||||
0.787709 Logistic Regression
|
||||
0.770950 Naive Bayes
|
||||
0.743017 Perceptron
|
||||
Reference in New Issue
Block a user