This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
input_arr = numpy.array([ | |
[10, 20, 30], | |
[40, 50, 60], | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Numpy module | |
import numpy as np | |
# Creating a 1-D list (horizontal) | |
list1 = [2, 3, 5] | |
# Creating a 1-D list (vertical) | |
list2 = [ | |
[20], | |
[30], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
baseline_accuracy_score = y_test.value_counts()[0] / len(y_test) | |
print(f'Model performance. : {accuracy}') | |
print(f'Baseline performance: {baseline_accuracy_score}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import accuracy_score | |
accuracy = accuracy_score(y_test, y_pred) | |
print(f'Accuracy score: {accuracy}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y_pred = classifier.predict(X_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_test = X_test_raw.copy() | |
# Add columns | |
X_test['can_vote'] = X_test['Age'].apply(lambda age: 1 if age >= 18 else 0) | |
X_test.loc[:, 'cabin_letter'] = X_test['Cabin'].apply( | |
lambda cabin: cabin[0] if cabin and type(cabin) is str else None, | |
) | |
# Remove columns | |
X_test = X_test.drop(columns=['Name', 'PassengerId']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classifier.fit(X_train, y_train) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.linear_model import LogisticRegression | |
classifier = LogisticRegression(max_iter=10000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
features_to_use = [ | |
'Age', | |
'SibSp', | |
'Parch', | |
'Fare', | |
'can_vote', | |
] + new_column_names | |
X_train = df[features_to_use].copy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import OneHotEncoder | |
categorical_columns = ['Pclass', 'Sex', 'Embarked', 'cabin_letter'] | |
categorical_encoder = OneHotEncoder(handle_unknown='ignore') | |
categorical_encoder.fit(df[categorical_columns]) | |
# Add the new columns to the data | |
new_column_names = [] | |
for idx, cat_column_name in enumerate(categorical_columns): | |
values = categorical_encoder.categories_[idx] |