Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 215 additions & 0 deletions Assignment 1/210700_Paridhi_1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "0aea084f",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np \n",
"import pandas as pd\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"from math import sqrt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9de1a867",
"metadata": {},
"outputs": [],
"source": [
"df=pd.read_csv('Dataset.csv',na_values=np.nan)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22c597ba",
"metadata": {},
"outputs": [],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1498d023",
"metadata": {},
"outputs": [],
"source": [
"df.drop('CUST_ID',axis=1,inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11fa8a38",
"metadata": {},
"outputs": [],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b9a62c15",
"metadata": {},
"outputs": [],
"source": [
"df[\"CREDIT_LIMIT\"].fillna(df[\"CREDIT_LIMIT\"].mean(),inplace=True)\n",
"df[\"MINIMUM_PAYMENTS\"].fillna(df[\"MINIMUM_PAYMENTS\"].mean(),inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a6b42b0f",
"metadata": {},
"outputs": [],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5ea2ce88",
"metadata": {},
"outputs": [],
"source": [
"df.skew(axis=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35fff664",
"metadata": {},
"outputs": [],
"source": [
"for col in df:\n",
" df[col]=np.sqrt(df[col])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de455143",
"metadata": {},
"outputs": [],
"source": [
"df.skew(axis=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e03b082b",
"metadata": {},
"outputs": [],
"source": [
"for col in df:\n",
" plt.figure()\n",
" sns.histplot(df[col])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95409505",
"metadata": {},
"outputs": [],
"source": [
"correlation = df.corr()\n",
"plt.figure(figsize=(17,17))\n",
"sns.heatmap(correlation, vmax=1, square=True,annot=True,cmap='cubehelix')\n",
"\n",
"plt.title('Correlation ')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b0b0afd3",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.preprocessing import StandardScaler\n",
"df_std = StandardScaler().fit_transform(df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f2855667",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.decomposition import PCA\n",
"pca = PCA().fit(df_std)\n",
"plt.plot(np.cumsum(pca.explained_variance_ratio_))\n",
"plt.xlim(0,15,1)\n",
"plt.xlabel('Number of components')\n",
"plt.ylabel('Cumulative explained variance')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "533ca1cd",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.decomposition import PCA \n",
"sklearn_pca = PCA(n_components=7)\n",
"Y_sklearn = sklearn_pca.fit_transform(df_std)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b754a92e",
"metadata": {},
"outputs": [],
"source": [
"print(Y_sklearn)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4b3e9fe",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading