This file contains hidden or 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
| def transform_to_json(row): | |
| passenger_dict['Survived'] = row['Survived'] | |
| ticket_dict['Pclass'] = row['Pclass'] | |
| ticket_dict['Fare'] = row['Fare'] | |
| passenger_dict['Ticket'] = ticket_dict | |
| return json.dump(passenger_dict) |
This file contains hidden or 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
| import numpy as np | |
| import pandas as pd | |
| import tensorflow as tf | |
| tf.enable_eager_execution() | |
| training_df: pd.DataFrame = pd.DataFrame( | |
| data={ | |
| 'feature1': np.random.rand(10), | |
| 'feature2': np.random.rand(10), |
This file contains hidden or 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
| feature1 feature2 feature3 target | |
| 0 0.474587 0.036684 0.625155 1 | |
| 1 0.157049 0.430315 0.659612 2 | |
| 2 0.525072 0.106430 0.524478 2 | |
| 3 0.012953 0.287160 0.742407 1 | |
| 4 0.613194 0.767960 0.967474 2 | |
| 5 0.199329 0.304863 0.677769 0 | |
| 6 0.956099 0.330080 0.928238 0 | |
| 7 0.659677 0.920559 0.894692 1 | |
| 8 0.956639 0.781366 0.224493 0 |
This file contains hidden or 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
| import pandas as pd | |
| basic_index = pd.MultiIndex.from_product([[1, 2, 3], ['a', 'b', 'c']]) | |
| print(basic_index.values) |
This file contains hidden or 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
| from datetime import datetime | |
| import pandas as pd | |
| orders = pd.DataFrame( | |
| data={ | |
| 'customer': [1, 2, 3, 2, 3, 1, 1], | |
| 'order_date': [ | |
| datetime(2018, 1, 3), | |
| datetime(2018, 1, 5), | |
| datetime(2018, 1, 7), |
This file contains hidden or 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
| daily_orders = orders.groupby(['customer', 'order_date']).sum() | |
| print(daily_orders) |
This file contains hidden or 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
| unique_customers = daily_orders.index.unique(level='customer') | |
| date_range = pd.DatetimeIndex( | |
| start=datetime(2018, 1, 1), | |
| end=datetime(2018, 1, 10), | |
| freq='D' | |
| ) | |
| customer_date_index = ( | |
| pd.MultiIndex |
This file contains hidden or 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
| daily_orders = daily_orders.reindex(customer_date_index, fill_value=0) | |
| daily_orders['running_amount'] = ( | |
| daily_orders | |
| .reindex() | |
| .groupby('customer') | |
| .cumsum() | |
| ) | |
| print(daily_orders) |
This file contains hidden or 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
| import numpy as np | |
| from sklearn.base import BaseEstimator | |
| from sklearn.pipeline import Pipeline | |
| from sklearn.preprocessing import MinMaxScaler | |
| class MockBinaryClassifier(BaseEstimator): | |
| """Class to emulate a predictive model using a simple heuristic.""" |
This file contains hidden or 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
| model = MockBinaryClassifier() | |
| test_feature = np.array([[0], [0.5], [3], [-1]]) | |
| predictions = model.predict(test_feature) | |
| print(predictions) | |
OlderNewer