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
# STEP 1 | |
BASE_DIR = 'images/' | |
# STEP 2 | |
SUB_DIRS = [topic + '/' for topic in df['Topic'].unique()] | |
# Print a message to the user | |
print('Image Download Started...') | |
start_time = datetime.datetime.now() |
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
@app.route('/', methods=['GET', 'POST']) | |
def chart(): | |
selected_class = request.form.get('dropdown-select') | |
if selected_class == 0 or selected_class == None: | |
survived_chart, title_chart, hist_age = redraw(1) | |
else: | |
survived_chart, title_chart, hist_age = redraw(selected_class) | |
script_survived_chart, div_survived_chart = components(survived_chart) |
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 = data.drop('Survived', axis=1) | |
target = data['Survived'] | |
rfc = RandomForestClassifier(random_state=101) | |
rfecv = RFECV(estimator=rfc, step=1, cv=StratifiedKFold(10), scoring='accuracy') | |
rfecv.fit(X, target) |
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
def calculate_woe_iv(dataset, feature, target): | |
lst = [] | |
for i in range(dataset[feature].nunique()): | |
val = list(dataset[feature].unique())[i] | |
lst.append({ | |
'Value': val, | |
'All': dataset[dataset[feature] == val].count()[feature], | |
'Good': dataset[(dataset[feature] == val) & (dataset[target] == 0)].count()[feature], | |
'Bad': dataset[(dataset[feature] == val) & (dataset[target] == 1)].count()[feature] | |
}) |
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
correlated_features = set() | |
correlation_matrix = data.drop('Survived', axis=1).corr() | |
for i in range(len(correlation_matrix.columns)): | |
for j in range(i): | |
if abs(correlation_matrix.iloc[i, j]) > 0.8: | |
colname = correlation_matrix.columns[i] | |
correlated_features.add(colname) |
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
b0, b1 = 0.0, 1.0 | |
lr = 0.001 | |
epochs = 10000 | |
error = [] | |
# run 10000 times | |
for epoch in range(epochs): | |
# initialize to 0 -> cost of epoch, Jb_0, Jb_1 | |
epoch_cost, cost_b0, cost_b1 = 0, 0, 0 |
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
def get_books(topic_list): | |
# Generate full URLs from the argument provided by user | |
all_urls = [] | |
for topic in topic_list: | |
all_urls.append('http://books.toscrape.com/catalogue/category/books/{}/index.html'.format(topic)) | |
# Instantiate an empty list for holding the dictionary objects | |
all_books = [] |
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
ratings_df = pd.DataFrame() | |
ratings_df['Mean_Rating'] = data.groupby('title')['rating'].mean().values | |
ratings_df['Num_Ratings'] = data.groupby('title')['rating'].count().values | |
fig, ax = plt.subplots(figsize=(14, 7)) | |
ax.spines['top'].set_visible(False) | |
ax.spines['right'].set_visible(False) | |
ax.set_title('Rating vs. Number of Ratings', fontsize=24, pad=20) | |
ax.set_xlabel('Rating', fontsize=16, labelpad=20) |
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
data.sort_values(by='numRatings', ascending=False).drop_duplicates('movieId')[:10] |
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
num_ratings = pd.DataFrame(data.groupby('movieId').count()['rating']).reset_index() | |
data = pd.merge(left=data, right=num_ratings, on='movieId') | |
data.rename(columns={'rating_x': 'rating', 'rating_y': 'numRatings'}, inplace=True) |
NewerOlder