-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from sklearn.cluster import KMeans | ||
|
||
class DataAnalysis: | ||
def __init__(self, data): | ||
self.data = data | ||
|
||
def analyze_data(self): | ||
# Perform data cleaning and preprocessing | ||
self.data = self.data.dropna() | ||
self.data = pd.get_dummies(self.data, columns=['transaction_type']) | ||
|
||
# Perform data analysis | ||
kmeans = KMeans(n_clusters=3, random_state=0).fit(self.data[['amount', 'frequency']]) | ||
self.data['cluster'] = kmeans.labels_ | ||
|
||
# Perform statistical analysis | ||
summary_stats = self.data.describe() | ||
summary_stats.loc['count'] = len(self.data) | ||
summary_stats.loc['mean'] = np.mean(self.data) | ||
summary_stats.loc['std'] = np.std(self.data) | ||
|
||
return summary_stats |