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
g = sns.FacetGrid(wines, col="res_sugar_labels", | |
hue='wine_type') | |
g.map(plt.scatter, "fixed acidity", "alcohol", alpha=.7) | |
g.add_legend(); |
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
# example depicting representing 3-D continous data | |
# using color and facets | |
quantile_list = [0, .25, .5, .75, 1.] | |
quantile_labels = ['0', '25', '50', '75'] | |
wines['res_sugar_labels'] = pd.qcut(wines['residual sugar'], | |
q=quantile_list, labels=quantile_labels) | |
wines['alcohol_levels'] = pd.qcut(wines['alcohol'], | |
q=quantile_list, labels=quantile_labels) | |
g = sns.FacetGrid(wines, col="res_sugar_labels", | |
hue='alcohol_levels') |
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
# using size for the 3rd dimension | |
sc = sns.scatterplot(wines['fixed acidity'], wines['alcohol'], | |
size=wines['residual sugar']) | |
# using color for the 3rd dimension | |
sc = sns.scatterplot(wines['fixed acidity'], wines['alcohol'], | |
hue=wines['residual sugar'], alpha=0.9) |
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
# facets with histograms | |
fig = plt.figure(figsize = (10,4)) | |
title = fig.suptitle("Sulphates Content in Wine", fontsize=14) | |
fig.subplots_adjust(top=0.85, wspace=0.3) | |
ax1 = fig.add_subplot(1,2, 1) | |
ax1.set_title("Red Wine") | |
ax1.set_xlabel("Sulphates") | |
ax1.set_ylabel("Frequency") | |
ax1.set_ylim([0, 1200]) |
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
fig = plt.figure(figsize = (10, 4)) | |
title = fig.suptitle("Wine Type - Quality", fontsize=14) | |
fig.subplots_adjust(top=0.85, wspace=0.3) | |
ax1 = fig.add_subplot(1,2, 1) | |
ax1.set_title("Red Wine") | |
ax1.set_xlabel("Quality") | |
ax1.set_ylabel("Frequency") | |
rw_q = red_wine['quality'].value_counts() | |
rw_q = (list(rw_q.index), list(rw_q.values)) |
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
fig = plt.figure(figsize = (6, 4)) | |
title = fig.suptitle("Wine Quality Frequency", fontsize=14) | |
fig.subplots_adjust(top=0.85, wspace=0.3) | |
ax = fig.add_subplot(1,1, 1) | |
ax.set_xlabel("Quality") | |
ax.set_ylabel("Frequency") | |
w_q = wines['quality'].value_counts() | |
w_q = (list(w_q.index), list(w_q.values)) | |
ax.tick_params(axis='both', which='major', labelsize=8.5) |
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 classification_report | |
print(classification_report(y_true=test_sentiments, | |
y_pred=predictions, target_names=LABELS)) |
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 seaborn as sns | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
with tf.Session() as session: | |
cm = tf.confusion_matrix(test_sentiments, predictions).eval() | |
LABELS = ['negative', 'positive'] | |
sns.heatmap(cm, annot=True, xticklabels=LABELS, yticklabels=LABELS, fmt='g') |
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
# get location of saved best model | |
best_model_dir = results_df[results_df['Test Accuracy'] == results_df['Test Accuracy'].max()]['Model Dir'].values[0] | |
# load up model | |
embedding_feature = hub.text_embedding_column( | |
key='sentence', module_spec="https://tfhub.dev/google/universal-sentence-encoder/2", trainable=True) | |
dnn = tf.estimator.DNNClassifier( | |
hidden_units=[512, 128], | |
feature_columns=[embedding_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
results_df = pd.DataFrame.from_dict(results, orient="index") | |
results_df |