Skip to content

Commit

Permalink
segments py3
Browse files Browse the repository at this point in the history
  • Loading branch information
adarsh0806 committed Jan 23, 2018
1 parent 9fb4eee commit ebfa126
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 11 additions & 13 deletions projects/customer_segments/customer_segments.ipynb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Import libraries necessary for this project\n",
Expand All @@ -56,9 +54,9 @@
"try:\n",
" data = pd.read_csv(\"customers.csv\")\n",
" data.drop(['Region', 'Channel'], axis = 1, inplace = True)\n",
" print \"Wholesale customers dataset has {} samples with {} features each.\".format(*data.shape)\n",
" print(\"Wholesale customers dataset has {} samples with {} features each.\".format(*data.shape))\n",
"except:\n",
" print \"Dataset could not be loaded. Is the dataset missing?\""
" print(\"Dataset could not be loaded. Is the dataset missing?\")"
]
},
{
Expand Down Expand Up @@ -104,7 +102,7 @@
"\n",
"# Create a DataFrame of the chosen samples\n",
"samples = pd.DataFrame(data.loc[indices], columns = data.keys()).reset_index(drop = True)\n",
"print \"Chosen samples of wholesale customers dataset:\"\n",
"print(\"Chosen samples of wholesale customers dataset:\")\n",
"display(samples)"
]
},
Expand Down Expand Up @@ -330,7 +328,7 @@
" step = None\n",
" \n",
" # Display the outliers\n",
" print \"Data points considered outliers for the feature '{}':\".format(feature)\n",
" print(\"Data points considered outliers for the feature '{}':\".format(feature))\n",
" display(log_data[~((log_data[feature] >= Q1 - step) & (log_data[feature] <= Q3 + step))])\n",
" \n",
"# OPTIONAL: Select the indices for data points you wish to remove\n",
Expand Down Expand Up @@ -704,7 +702,7 @@
"source": [
"# Display the predictions\n",
"for i, pred in enumerate(sample_preds):\n",
" print \"Sample point\", i, \"predicted to be in Cluster\", pred"
" print(\"Sample point\", i, \"predicted to be in Cluster\", pred)"
]
},
{
Expand Down Expand Up @@ -820,21 +818,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions projects/customer_segments/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pca_results(good_data, pca):
dimensions = dimensions = ['Dimension {}'.format(i) for i in range(1,len(pca.components_)+1)]

# PCA components
components = pd.DataFrame(np.round(pca.components_, 4), columns = good_data.keys())
components = pd.DataFrame(np.round(pca.components_, 4), columns = list(good_data.keys()))
components.index = dimensions

# PCA explained variance
Expand Down Expand Up @@ -132,7 +132,7 @@ def channel_results(reduced_data, outliers, pca_samples):
try:
full_data = pd.read_csv("customers.csv")
except:
print "Dataset could not be loaded. Is the file missing?"
print("Dataset could not be loaded. Is the file missing?")
return False

# Create the Channel DataFrame
Expand Down

0 comments on commit ebfa126

Please sign in to comment.