junshan-kit 2.1.4__py2.py3-none-any.whl → 2.1.7__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+
2
+ import pandas as pd
3
+ import os
4
+ from sklearn.preprocessing import StandardScaler
5
+ import junshan_kit.datahub
6
+
7
+ class CSVToPandas:
8
+ def __init__(self):
9
+ self.data_downloader = junshan_kit.datahub.kaggle_data()
10
+
11
+
12
+ def read_csv(self, data_name):
13
+ self.csv_path = f'exp_data/{data_name}/{data_name}.csv'
14
+ if not os.path.exists(self.csv_path):
15
+ self.data_downloader.download_data(f'{data_name}', f'exp_data/{data_name}')
16
+
17
+ # ----------------- ccfd_kaggle ----------------------------------
18
+ def ccfd_kaggle(self, data_name = 'ccfd-kaggle', show_info = True):
19
+ # download data if not exist
20
+ self.read_csv(data_name)
21
+
22
+ df = pd.read_csv(self.csv_path)
23
+ m_before, n_before = df.shape
24
+ df = df.dropna(axis=0, how='any')
25
+ m_after, n_after = df.shape
26
+ df['Class'] = df['Class'].replace(0, -1)
27
+
28
+ if show_info:
29
+ pos_count = (df['Class'] == 1).sum()
30
+ neg_count = (df['Class'] == -1).sum()
31
+
32
+ print('\n' + '='*60)
33
+ print(f"{'CCFD-Kaggle Dataset Info':^60}")
34
+ print('='*60)
35
+ print(f"{'Original size:':<25} {m_before} rows x {n_before} cols")
36
+ print(f"{'Size after dropping NaNs:':<25} {m_after} rows x {n_after} cols")
37
+ print(f"{'Positive samples (+1):':<25} {pos_count}")
38
+ print(f"{'Negative samples (-1):':<25} {neg_count}")
39
+ print(f"{'Export size:':<25} {m_after} rows x {n_after} cols")
40
+ print('-'*60)
41
+ print(f"More details: https://www.jianguoyun.com/p/Dd1clVgQ4ZThCxiwzZQGIAA")
42
+ print('='*60 + '\n')
43
+
44
+ return df
45
+
46
+ # ------------------------
47
+ def ghpdd_kaggle(self, data_name='ghpdd-kaggle', show_info=True):
48
+ # download data if not exist
49
+ self.read_csv(data_name)
50
+
51
+ # read csv
52
+ df = pd.read_csv(self.csv_path)
53
+ m_before, n_before = df.shape
54
+
55
+ # drop NaNs
56
+ df = df.dropna(axis=0, how='any')
57
+ m_after, n_after = df.shape
58
+
59
+ # drop unique identifier
60
+ if 'property_id' in df.columns:
61
+ df.drop(columns=['property_id'], inplace=True)
62
+
63
+ # Replace label 0 with -1
64
+ df['decision'] = df['decision'].replace(0, -1)
65
+
66
+ # Identify categorical and numerical columns
67
+ cat_cols = ['country', 'city', 'property_type', 'furnishing_status']
68
+ num_cols = [col for col in df.columns if col not in cat_cols + ['decision']]
69
+
70
+ # One-Hot encode categorical columns
71
+ df = pd.get_dummies(df, columns=cat_cols)
72
+
73
+ # Convert boolean columns to int
74
+ bool_cols = df.select_dtypes(include='bool').columns
75
+ for col in bool_cols:
76
+ df[col] = df[col].astype(int)
77
+
78
+ # Standardize numerical columns
79
+ scaler = StandardScaler()
80
+ df[num_cols] = scaler.fit_transform(df[num_cols])
81
+
82
+ # 导出后的大小
83
+ m_export, n_export = df.shape
84
+
85
+ if show_info:
86
+ pos_count = (df['decision'] == 1).sum()
87
+ neg_count = (df['decision'] == -1).sum()
88
+
89
+ print('\n' + '='*70)
90
+ print(f"{'GHPDD-Kaggle Dataset Info':^70}")
91
+ print('='*70)
92
+ print(f"{'Original size:':<35} {m_before} rows x {n_before} cols")
93
+ print(f"{'Size after dropping NaNs:':<35} {m_after} rows x {n_after} cols")
94
+ print(f"{'Export size (after encoding & scaling):':<35} {m_export} rows x {n_export} cols")
95
+ print(f"{'Positive samples (+1):':<35} {pos_count}")
96
+ print(f"{'Negative samples (-1):':<35} {neg_count}")
97
+ print('-'*70)
98
+ print(f"{'Note: categorical columns one-hot encoded, numerical standardized.':^70}")
99
+ print(f"More details: https://www.jianguoyun.com/p/DU6Lr9oQqdHDDRj5sI0GIAA")
100
+ print('='*70 + '\n')
101
+
102
+ return df
103
+
104
+
105
+
junshan_kit/datahub.py CHANGED
@@ -42,6 +42,9 @@ class kaggle_data:
42
42
  # example: read_data(copy_path='./exp_data')
43
43
 
44
44
 
45
+
46
+
47
+
45
48
  if __name__ == "__main__":
46
49
  # Your code here
47
50
  data = kaggle_data()
junshan_kit/test.py ADDED
@@ -0,0 +1,5 @@
1
+ import DataProcessor
2
+
3
+
4
+ data_loader = DataProcessor.CSVToPandas()
5
+ data_loader.ghpdd_kaggle()
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: junshan_kit
3
- Version: 2.1.4
3
+ Version: 2.1.7
4
4
  Summary: This is an optimization tool.
5
5
  Author-email: Junshan Yin <junshanyin@163.com>
6
6
  Requires-Dist: kaggle==1.7.4.5
7
7
  Requires-Dist: kagglehub==0.3.13
8
8
  Requires-Dist: numpy==2.2.6
9
+ Requires-Dist: pandas==2.3.3
9
10
  Requires-Dist: scikit-learn==1.7.1
10
11
  Description-Content-Type: text/markdown
11
12
 
@@ -0,0 +1,7 @@
1
+ junshan_kit/DataProcessor.py,sha256=rp_w325h8EvKcLMSa12w5B-UA8G75O1qP0ogE6GDSE0,3886
2
+ junshan_kit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ junshan_kit/datahub.py,sha256=BWcG_TPW1xf_y_GzxRXanuOAB01WugBiO5r53EDbr8s,1815
4
+ junshan_kit/test.py,sha256=jyZQPgX40HlLM23vGMbuZFwFBk7YiFqzzh9xuOTzbw8,91
5
+ junshan_kit-2.1.7.dist-info/METADATA,sha256=ePQG7bT7y7yVU7iSI3CxnfNacwJLyAlSB7nEmAG3_NM,599
6
+ junshan_kit-2.1.7.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
7
+ junshan_kit-2.1.7.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- junshan_kit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- junshan_kit/datahub.py,sha256=H5Er9sowGyPhBLEg1UFGYwVLOtGUkonxnVjkWwxixOY,1812
3
- junshan_kit-2.1.4.dist-info/METADATA,sha256=Mxa0XwUl-hgpri-PTzhPVu5j0OG2Tt8GY3Y0EGazTzM,570
4
- junshan_kit-2.1.4.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
5
- junshan_kit-2.1.4.dist-info/RECORD,,