This file contains hidden or 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 univariate_hist_with_hue(x = 'person_age', hue = 'person_income'): | |
plt.figure(dpi = 130) | |
sns.set_style('whitegrid') | |
return sns.kdeplot(x = x, data = df, fill=True, palette = 'crest', hue = hue).set_title('Univariate visualization of Quantative Variable with hue') | |
D = interact(univariate_hist_with_hue, | |
x = widgets.Dropdown( | |
options = ['person_age','person_income','person_emp_length','loan_amnt','loan_int_rate','loan_percent_income','cb_person_cred_hist_length'] | |
), | |
hue = widgets.Dropdown( |
This file contains hidden or 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 univariate_hist(x = 'person_age'): | |
plt.figure(dpi = 130) | |
sns.set_style('whitegrid') | |
return sns.kdeplot(x = x, data = df, fill=True, palette = 'crest').set_title('Univariate visualization of Quantative Variable') | |
C = interact(univariate_hist, | |
x = widgets.Dropdown( | |
options = ['person_age','person_income','person_emp_length','loan_amnt','loan_int_rate','loan_percent_income','cb_person_cred_hist_length'] | |
) | |
) |
This file contains hidden or 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 scatter_plot_int_with_hue(x = 'person_age',y = 'person_income', hue = 'loan_grade'): | |
plt.figure(dpi = 120) | |
sns.set_style('whitegrid') | |
return sns.scatterplot(data = df, x = x,y = y, alpha = 0.6, hue = hue, cmap = 'Set2').set_title('Visualize Relation Between 2 Quantative Variables with Hue') | |
B = interact(scatter_plot_int_with_hue, | |
x = widgets.Dropdown( | |
options = ['person_age','person_income','person_emp_length','loan_amnt','loan_int_rate','loan_percent_income','cb_person_cred_hist_length'] | |
), | |
y = widgets.Dropdown( |
This file contains hidden or 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 scatter_plot_int(x = 'person_age',y = 'person_income'): | |
plt.figure(dpi = 120) | |
sns.set_style('whitegrid') | |
return sns.scatterplot(data = df, x = x,y = y, alpha = 0.6, ).set_title('Visualize Relation Between 2 Quantative Variables') | |
A = interact(scatter_plot_int, | |
x = widgets.Dropdown( | |
options = ['person_age','person_income','person_emp_length','loan_amnt','loan_int_rate','loan_percent_income','cb_person_cred_hist_length'] | |
), | |
y = widgets.Dropdown( | |
options = ['person_age','person_income','person_emp_length','loan_amnt','loan_int_rate','loan_percent_income','cb_person_cred_hist_length'] |
This file contains hidden or 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
## Highliting losses in the dataframe | |
def color_negative_values(value): | |
""" | |
This function takes in values of dataframe | |
if particular value is negative it is colored as redwhich implies loss | |
if value is greater than one it implies higher profit | |
""" | |
if value < 0: | |
color = '#ff8a8a' | |
elif value > 1: |
This file contains hidden or 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
_ = interact(plot_histogram, | |
palette = widgets.Dropdown( | |
options = ['pastel','husl','Set2','flare','crest','magma','icefire'] | |
), | |
kde = widgets.RadioButtons( | |
options = [True,False], | |
disabled = False), | |
hue = widgets.ToggleButtons( | |
options = ['categories','other categories'], | |
tooltip = ['categories','other categories'], |
This file contains hidden or 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 plot_histogram(bins = 10, hue = 'categories', kde = False, palette = 'Blues', x_range_1 = (-3,3)): | |
"""plots histogram | |
params: | |
======= | |
bins: int | |
histogram bins | |
hue: str | |
categorical columns to color | |
kde: bool | |
wether to show kde plot |
This file contains hidden or 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
als = ALS(maxIter = 10 , | |
userCol = "user_id", | |
itemCol = "isbn_indexed", | |
ratingCol = "book_rating", | |
nonnegative = True, | |
coldStartStrategy = 'drop') | |
from pyspark.ml.tuning import ParamGridBuilder,CrossValidator | |
grid = ParamGridBuilder().addGrid(als.rank, [10,30])\ | |
.addGrid(als.regParam, [0.2,0.01,1,2])\ |
This file contains hidden or 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 pyspark.ml.recommendation import ALS | |
from pyspark.ml.evaluation import RegressionEvaluator | |
training, test = indexed.randomSplit([0.8,0.1]) | |
als = ALS(maxIter = 10 , | |
regParam = 0.9, | |
userCol = "user_id", | |
itemCol = "isbn_indexed", | |
ratingCol = "book_rating", |
This file contains hidden or 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 pyspark.ml.recommendation import ALS | |
from pyspark.ml.evaluation import RegressionEvaluator | |
from pyspark.ml.feature import StringIndexer | |
indexer = StringIndexer(inputCol = "isbn", outputCol = "isbn_indexed") | |
indexed = indexer.fit(filtered_with_location).transform(filtered_with_location)\ | |
.withColumn('isbn_indexed',F.col('isbn_indexed')\ | |
.cast("int"))\ | |
.drop('isbn') |