{{ message }}

Instantly share code, notes, and snippets.

🔥

# DANGerous tommydangerous

🔥
Created Jun 17, 2021
create_matrix.py
View create_matrix.py
 import numpy input_arr = numpy.array([ [10, 20, 30], [40, 50, 60], ])
Created Jun 17, 2021
create_vectors.py
View create_vectors.py
 # 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],
Created Jun 11, 2021
baseline_accuracy.py
View baseline_accuracy.py
 baseline_accuracy_score = y_test.value_counts()[0] / len(y_test) print(f'Model performance. : {accuracy}') print(f'Baseline performance: {baseline_accuracy_score}')
Created Jun 11, 2021
calculate_model_accuracy.py
View calculate_model_accuracy.py
 from sklearn.metrics import accuracy_score accuracy = accuracy_score(y_test, y_pred) print(f'Accuracy score: {accuracy}')
Created Jun 11, 2021
predict_test_data.py
View predict_test_data.py
 y_pred = classifier.predict(X_test)
Created Jun 11, 2021
prepare_test_data.py
View prepare_test_data.py
 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'])
Created Jun 11, 2021
train_model.py
View train_model.py
 classifier.fit(X_train, y_train)
Created Jun 11, 2021
choose_algorithm.py
View choose_algorithm.py
 from sklearn.linear_model import LogisticRegression classifier = LogisticRegression(max_iter=10000)
Created Jun 11, 2021
select_features.py
View select_features.py
 features_to_use = [ 'Age', 'SibSp', 'Parch', 'Fare', 'can_vote', ] + new_column_names X_train = df[features_to_use].copy()
Created Jun 11, 2021
encode_values.py
View encode_values.py
 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]