-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datasets): Add cardiovascular data
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
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
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,35 @@ | ||
import pandas as pd | ||
|
||
from sklearn.preprocessing import OneHotEncoder, StandardScaler | ||
from sklearn.pipeline import Pipeline | ||
from sklearn.compose import ColumnTransformer | ||
|
||
from pmlb import fetch_data | ||
|
||
def transformations(auto=True): | ||
if auto: | ||
data = fetch_data('adult') | ||
else: | ||
data = fetch_data('adult') | ||
|
||
numerical_features = ['age', 'fnlwgt', | ||
'capital-gain', 'capital-loss', | ||
'hours-per-week'] | ||
numerical_transformer = Pipeline(steps=[ | ||
('onehot', StandardScaler())]) | ||
|
||
categorical_features = ['workclass','education', 'marital-status', | ||
'occupation', 'relationship', | ||
'race', 'sex'] | ||
categorical_transformer = Pipeline(steps=[ | ||
('onehot', OneHotEncoder(handle_unknown='ignore'))]) | ||
|
||
preprocessor = ColumnTransformer( | ||
transformers=[ | ||
('num', numerical_transformer, numerical_features), | ||
('cat', categorical_transformer, categorical_features)]) | ||
|
||
processed_data = preprocessor.fit_transform(data) | ||
processed_data = pd.DataFrame.sparse.from_spmatrix(preprocessor.fit_transform(processed_data)) | ||
return data, processed_data, preprocessor | ||
|
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,19 @@ | ||
import pandas as pd | ||
|
||
from sklearn.preprocessing import StandardScaler | ||
from sklearn.pipeline import Pipeline | ||
from sklearn.compose import ColumnTransformer | ||
|
||
from pmlb import fetch_data | ||
|
||
def transformations(auto=True): | ||
if auto: | ||
data = fetch_data('breast_cancer_wisconsin') | ||
else: | ||
data = fetch_data('breast_cancer_wisconsin') | ||
scaler = StandardScaler() | ||
processed_data = scaler.fit_transform(data) | ||
processed_data = pd.DataFrame(processed_data) | ||
return data, processed_data, scaler | ||
|
||
|
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,25 @@ | ||
import pandas as pd | ||
|
||
from sklearn.preprocessing import OneHotEncoder, StandardScaler | ||
from sklearn.pipeline import Pipeline | ||
from sklearn.compose import ColumnTransformer | ||
|
||
def transformations(data): | ||
categorical_features = ['gender', 'cardio', 'active', 'alco', 'smoke', 'gluc', | ||
'cholesterol'] | ||
numerical_features = [ 'height', 'weight', 'ap_hi', 'ap_lo'] | ||
|
||
numerical_transformer = Pipeline(steps=[ | ||
('onehot', StandardScaler())]) | ||
|
||
categorical_transformer = Pipeline(steps=[ | ||
('onehot', OneHotEncoder(handle_unknown='ignore'))]) | ||
|
||
preprocessor = ColumnTransformer( | ||
transformers=[ | ||
('num', numerical_transformer, numerical_features), | ||
('cat', categorical_transformer, categorical_features)]) | ||
|
||
processed_data = preprocessor.fit_transform(data) | ||
processed_data = pd.DataFrame.sparse.from_spmatrix(preprocessor.fit_transform(processed_data)) | ||
return processed_data, preprocessor |